0
votes

I need to summarize dax table and filter it by date range 5 month back from last EffectiveDate, which is 7/27/2019

So my dax expression:

TestTable1 = 
VAR LastEffDate = LASTDATE(fact_Premium[EffectiveDate])  // --  7/27/2019
RETURN 
SUMMARIZE(
      FILTER(dim_Date, DATEDIFF(DATEADD(STARTOFMONTH(LastEffDate), -5,MONTH), ENDOFMONTH(LastEffDate), MONTH)),
      dim_Date[Year Month],
       "Premium", [Ttl WP]
       ) 

But for some reason it brings me data for all years in a dataset:

enter image description here

I also tried:

TestTable1 = 
    VAR LastEffDate = LASTDATE(fact_Premium[EffectiveDate])  // --  7/27/2019
RETURN 
    SUMMARIZE (
        FILTER (
             dim_Date, 
             DATESBETWEEN(dim_Date[Date],
                 DATE(2019,5,1),               
                 DATE(2019,6,1)
             )
        ),
        dim_Date[Year Month],
        "Premium", [Ttl WP]
    ) 

But it gives me an error:

A table of multiple values was supplied where a single value was expected.

Am I missing something here?

2
what does your filter expression evaluates to?Pratik Bhavsar
Can you provide a *.pbix file with data sample?Nick Krasnov

2 Answers

2
votes

Your filter expression should be using DATESBETWEEN and not the datediff:

TestTable1 = 
    VAR LastEffDate = LASTDATE(fact_Premium[EffectiveDate])  // --  7/27/2019
RETURN 
    SUMMARIZE (
        FILTER (
             dim_Date, 
             DATESBETWEEN(
                 //expression for start date, 
                 //expression for end date
             )
        ),
        dim_Date[Year Month],
        "Premium", [Ttl WP]
    ) 
0
votes

I think you are still missing aggregating your Premium,

SUM(Ttl WP)

TestTable1 =
VAR LastEffDate =
    LASTDATE ( fact_Premium[EffectiveDate] ) // --  7/27/2019
RETURN
    SUMMARIZE (
        FILTER (
            dim_Date,
            DATESBETWEEN ( dim_Date[Date], DATE ( 2019, 5, 1 ), DATE ( 2019, 6, 1 ) )
        ),
        dim_Date[Year Month],
        "Premium", SUM ( [Ttl WP] ) ---- Need to aggregate here
    )