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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
DianeUmu
Regular Visitor

DAX Formula

Hello,

DianeUmu_0-1703001646708.png

I'm using the above DAX to get selected month values and same period last year value of the selected date and I want now to calculate the difference between the 2. Below is the result from above DAX.

DianeUmu_1-1703001782779.png

I need to calculate difference between the two dates, 11/30/2023 being selected date and 11/22/2022 being start date.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @DianeUmu ,

 

You can try the following Dax.

Test =
var _mindate=
IF(
    [SMRR Gain]=BLANK(),BLANK(),
MINX(FILTER(ALLSELECTED('vm_fct_store_month_360'),[SMRR Gain]<>BLANK()),[LAST_CALENDAR_DATE]))
var _maxdate=
IF(
    [SMRR Gain]=BLANK(),BLANK(),
MAXX(FILTER(ALLSELECTED('vm_fct_store_month_360'),[SMRR Gain]<>BLANK()),[LAST_CALENDAR_DATE]))
return
SUMX(    FILTER(ALLSELECTED('vm_fct_store_month_360'),'vm_fct_store_month_360'[LAST_CALENDAR_DATE]=_mindate),[SMRR Gain])
-
SUMX( FILTER(ALLSELECTED('vm_fct_store_month_360'),'vm_fct_store_month_360'[LAST_CALENDAR_DATE]=_maxdate),[SMRR Gain])

vyangliumsft_0-1703057927742.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @DianeUmu ,

 

You can try the following Dax.

Test =
var _mindate=
IF(
    [SMRR Gain]=BLANK(),BLANK(),
MINX(FILTER(ALLSELECTED('vm_fct_store_month_360'),[SMRR Gain]<>BLANK()),[LAST_CALENDAR_DATE]))
var _maxdate=
IF(
    [SMRR Gain]=BLANK(),BLANK(),
MAXX(FILTER(ALLSELECTED('vm_fct_store_month_360'),[SMRR Gain]<>BLANK()),[LAST_CALENDAR_DATE]))
return
SUMX(    FILTER(ALLSELECTED('vm_fct_store_month_360'),'vm_fct_store_month_360'[LAST_CALENDAR_DATE]=_mindate),[SMRR Gain])
-
SUMX( FILTER(ALLSELECTED('vm_fct_store_month_360'),'vm_fct_store_month_360'[LAST_CALENDAR_DATE]=_maxdate),[SMRR Gain])

vyangliumsft_0-1703057927742.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Liu, The formula worked, However I want to have the difference between the two dates in the same measure and the output should look like this

DianeUmu_0-1705510462896.png

Basically have differenece value next to 11/30/2023.
Please advice.

And using the formula that you provided, It's giving me the same amount for the 2 dates without the difference.

DianeUmu_1-1705510939129.png

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.