Pergunta

I'm studying SQL Server Tabular model.
I'm struggle to transfer a MDX equation to DAX equation.

I want to show every month's PC count changing(incremental or decremental) rate using following calculation.
(current month PC count - previous month PC count) / previous month PC Count

This is MDX equation and it is working well in multi-dimensional model.
[PC Count] is Last non-empty value.

(([Date].[Fiscal QTR].CURRENTMEMBER, [Measures].[PC Count])
-
([Date].[Fiscal QTR].PREVMEMBER, [Measures].[PC Count]))
/
([Date].[Fiscal QTR].PREVMEMBER, [Measures].[PC Count])

I made a DAX equation for current month PC count

PC Count:=
CALCULATE(
    SUM([PC Count]),
    FILTER(Time, Time[DateKey] = MAX(vwFact_PCCount[DateKey]))
)

This is working well in Grid view(SSDT) and Performance Point. but the following MDX equation for previous month PC Count is working well in grid view(SSDT) but this equation shows error in Performance Point when I bottom axis(month).

Previous Month Count:=CALCULATE(
    SUM([PC Count]),
    FILTER(Time, Time[DateKey] = FORMAT(DATE(LEFT(Max(vwFact_PCCount[DateKey]),4),
                                             RIGHT(LEFT(Max(vwFact_PCCount[DateKey]),6),2)
                                             ,1)-1
                                        , "yyyyMMdd") *1)
)

I don't know what is wrong my Previous Month Count equation. How can I get this result using DAX?

Foi útil?

Solução

Your "current month PC count" expression is written such that it will always be the most recent month in the table. This is not the same as the MDX code you show in your post.

MDX - Current Month PC Count

([Date].[Calendar Month].CURRENTMEMBER, [Measures].[PC Count])

DAX - Current Month PC Count

SUM('table name'[PC Count])

In DAX, the concept of "current" is contextual...See this thread on the MSDN forums for a good discussion.

Here's an example showing a current/previous situation in DAX using AdventureWorksDW2012 dataset:

DEFINE
    MEASURE 'Internet Sales'[SalesAmount_CurrMth] = 
        'Internet Sales'[Internet Total Sales]
    MEASURE 'Internet Sales'[SalesAmount_PrevMth] = 
        CALCULATE (
             'Internet Sales'[SalesAmount_CurrMth]
            ,PREVIOUSMONTH('Date'[Date])
        )
EVALUATE (
    FILTER(
        ADDCOLUMNS (
            SUMMARIZE (
                'Date'
                ,'Date'[Calendar Year]
                ,'Date'[Month Name]
            )
            ,"Current Month", 'Internet Sales'[SalesAmount_CurrMth]
            ,"Prior Month", 'Internet Sales'[SalesAmount_PrevMth]
        )
        ,'Internet Sales'[SalesAmount_CurrMth] <> BLANK()
    )
)

try this...

Previous Month Count :=
CALCULATE (
     SUM('<insert table name here>'[PC Count])
    ,DATEADD('Date'[Date],-1, MONTH)
)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top