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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bammyd
Frequent Visitor

Display the latest MoM & YoY difference and percentage for selected Country

Hello.

Please see the Sample_Table below.

Using Country as the slicer, I want to create a measure that displays the latest MoM & YoY variance on a Card (i.e. Total_Cost - Previous_Mth). I also have a Calendar table.

 

Sample_Table

CountryCodePriceTime seriesYear
USAUSA55001-Dec-232023
CanadaCAN31001-Dec-232023
MexicoMEX42001-Dec-232023
CanadaCAN62001-Jan-242024
MexicoMEX40001-Jan-242024
USAUSA46001-Jan-242024
CanadaCAN38001-Feb-242024
USAUSA60001-Feb-242024
MexicoMEX53001-Feb-242024
CanadaCAN45001-Mar-242024
USAUSA46501-Mar-242024
MexicoMEX55001-Mar-242024

 

 

I have the following measures.

Total_Cost = SUM(SampleTable[Price])

Previous_Mth = CALCULATE ([TotalCost], PREVIOUSMONTH (Calendar[Date]))

MoM_Variance = [Total_Cost] - [Previous_Mth]

 
Latest_MoM_Variance =
 CALCULATE([MoM_Variance]),
    FILTER(
        SampleTable,
          Sample_Table[Time series] = MAX(SampleTable[Time series])
    ))

The measures above did not display the correct value, I want to be able to select Canada on the slicer and see the MOM & YoY variance for 01-Mar-2024.

 

Thank you.

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @amitchandak , please allow me to provide another insight: 
Hi  @bammyd ,

You can try the following DAX:

MoM_Variance =
var _select=SELECTEDVALUE('Table'[Country])
var _Total_Cost=SUM('Table'[Price])
var _today=TODAY()
var _Previous_Mth=
SUMX(FILTER(ALL('Table'),'Table'[Country]=_select&&'Table'[Time series]>EOMONTH(_today,-2)&&'Table'[Time series]<=EOMONTH(_today,-1)),[Price])
return
_Total_Cost-_Previous_Mth

vyangliumsft_0-1713505183743.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

4 REPLIES 4
v-yangliu-msft
Community Support
Community Support

Thanks for the reply from @amitchandak , please allow me to provide another insight: 
Hi  @bammyd ,

You can try the following DAX:

MoM_Variance =
var _select=SELECTEDVALUE('Table'[Country])
var _Total_Cost=SUM('Table'[Price])
var _today=TODAY()
var _Previous_Mth=
SUMX(FILTER(ALL('Table'),'Table'[Country]=_select&&'Table'[Time series]>EOMONTH(_today,-2)&&'Table'[Time series]<=EOMONTH(_today,-1)),[Price])
return
_Total_Cost-_Previous_Mth

vyangliumsft_0-1713505183743.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.

Thank you for your response @v-yangliu-msft but the result I want is to see the latest MoM & YoY difference which is in March 2024. So for example; when I select USA the value will be -135, for Mexico = 20 and Canada = 70. Hope this clarifies things a bit. thank you.

bammyd_1-1714096318985.png

 

 

amitchandak
Super User
Super User

@bammyd , Try measures like, with help from date/calendar table

 


This Month =
var _max = eomonth(if(isfiltered('Date'),MAX( 'Date'[Date]) , today()),0)
var _min = eomonth(_max,-1)+1 ,
return
CALCULATE([MoM_Variance] ,DATESBETWEEN('Date'[Date],_min,_max))

 

 

Last Month =
var _max1 = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _max = eomonth(_max1,-1)
var _min = eomonth(_max1,-2)+1
return
CALCULATE([MoM_Variance] ,DATESBETWEEN('Date'[Date],_min,_max))

 

MTD if needed

MTD =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = eomonth(_max,-1)+1 ,
return
CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

Thank you for your response @amitchandak  but what I want is Country as the Slicer so when ISFILTERED Country, I want the card to display the MoM_Variance value for 1 Mar 2024 for the selected country. Thank you

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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