Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
sandip
Helper III
Helper III

how to use comma separated value as a filter in calculate function in dax

Hi,

I am using below dax expression:

totalGrossPurchase =
var vDate = DATE(YEAR(SELECTEDVALUE(CAL4[Current_End])), Month(SELECTEDVALUE(CAL4[Current_End])), 01)

var v11MonthsBeforDt = DATE(YEAR(vDate),MONTH(vDate)-11,DAY(vDate))
var v11MonthsBeforMonthName = TRIM(FORMAT(v11MonthsBeforDt, "YYYY-MMM"))

var v10MonthsBeforDt = DATE(YEAR(vDate),MONTH(vDate)-10,DAY(vDate))
var v10MonthsBeforMonthName = TRIM(format(v10MonthsBeforDt, "YYYY-MMM"))

var v9MonthsBeforDt = DATE(YEAR(vDate),MONTH(vDate)-9,DAY(vDate))
var v9MonthsBeforMonthName = TRIM(format(v9MonthsBeforDt, "YYYY-MMM"))

/*var vFinalYearMonthTxt = v11MonthsBeforMonthName&","&v10MonthsBeforMonthName&","&v9MonthsBeforMonthName*/
return CALCULATE(SUM('SAVO_QBR_TEMP'[TOTAL GROSS SALES]), PATHCONTAINS("2018-Mar,2018-Feb", Dates[YearMonthText]))
 
But it does not work for me. Please tell me where I am worng
 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@sandip , try this DAX code:

 

totalGrossPurchase =
VAR vDate =
    DATE ( YEAR (
        SELECTEDVALUE ( CAL4[Current_End] )
    ), MONTH (
        SELECTEDVALUE ( CAL4[Current_End] )
    ), 01 )
VAR v11MonthsBeforDt =
    DATE ( YEAR ( vDate ), MONTH ( vDate ) - 11, DAY ( vDate ) )
VAR v11MonthsBeforMonthName =
    TRIM (
        FORMAT (
            v11MonthsBeforDt,
            "YYYY-MMM"
        )
    )
VAR v10MonthsBeforDt =
    DATE ( YEAR ( vDate ), MONTH ( vDate ) - 10, DAY ( vDate ) )
VAR v10MonthsBeforMonthName =
    TRIM (
        FORMAT (
            v10MonthsBeforDt,
            "YYYY-MMM"
        )
    )
VAR v9MonthsBeforDt =
    DATE ( YEAR ( vDate ), MONTH ( vDate ) - 9, DAY ( vDate ) )
VAR v9MonthsBeforMonthName =
    TRIM (
        FORMAT (
            v9MonthsBeforDt,
            "YYYY-MMM"
        )
    )
VAR Result =
    CALCULATE (
        SUM ( 'SAVO_QBR_TEMP'[TOTAL GROSS SALES] ),
        Dates[YearMonthText]
            IN {
            v11MonthsBeforMonthName,
            v10MonthsBeforMonthName,
            v9MonthsBeforMonthName
        }
    )
RETURN
    Result

 

I kept everything the same, and then added a new variable Result that does what you're looking for.

 

You could probably build a similar filter only using the date column to get only the dates between 9 and 11 months before the selected period, that may be a little faster.

View solution in original post

1 REPLY 1
Anonymous
Not applicable

@sandip , try this DAX code:

 

totalGrossPurchase =
VAR vDate =
    DATE ( YEAR (
        SELECTEDVALUE ( CAL4[Current_End] )
    ), MONTH (
        SELECTEDVALUE ( CAL4[Current_End] )
    ), 01 )
VAR v11MonthsBeforDt =
    DATE ( YEAR ( vDate ), MONTH ( vDate ) - 11, DAY ( vDate ) )
VAR v11MonthsBeforMonthName =
    TRIM (
        FORMAT (
            v11MonthsBeforDt,
            "YYYY-MMM"
        )
    )
VAR v10MonthsBeforDt =
    DATE ( YEAR ( vDate ), MONTH ( vDate ) - 10, DAY ( vDate ) )
VAR v10MonthsBeforMonthName =
    TRIM (
        FORMAT (
            v10MonthsBeforDt,
            "YYYY-MMM"
        )
    )
VAR v9MonthsBeforDt =
    DATE ( YEAR ( vDate ), MONTH ( vDate ) - 9, DAY ( vDate ) )
VAR v9MonthsBeforMonthName =
    TRIM (
        FORMAT (
            v9MonthsBeforDt,
            "YYYY-MMM"
        )
    )
VAR Result =
    CALCULATE (
        SUM ( 'SAVO_QBR_TEMP'[TOTAL GROSS SALES] ),
        Dates[YearMonthText]
            IN {
            v11MonthsBeforMonthName,
            v10MonthsBeforMonthName,
            v9MonthsBeforMonthName
        }
    )
RETURN
    Result

 

I kept everything the same, and then added a new variable Result that does what you're looking for.

 

You could probably build a similar filter only using the date column to get only the dates between 9 and 11 months before the selected period, that may be a little faster.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

October NL Carousel

Fabric Community Update - October 2024

Find out what's new and trending in the Fabric Community.