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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
StevenT
Helper V
Helper V

Unable to get correct % of MOM difference - Part 2

Hello. Ashish Mathur was able to help me with the first part, getting MOM for a chart.
This is a part two to that, and a new question.

In addition to MoM, I'm looking to get QoQ and YoY.
these are my current tools and code.
the Matrix where my data is, the slicer based off of the field and parameter created (right)
StevenT_0-1726160011802.png

My code in my measure is below.
I first tried the selectvalue function but it was incompatible with the field parameter, and I tried it with 1 and "1".  neither solved the problem.
I then created an IF code and that doesn't seem to allow me to switch based on user choice.
I'm stuck on this code below.
______________________________________________________________________________________________________________________

Calc % =
VAR CurrentMonthSales = SUM('TrackSales'[SalesAmt])
VAR PreviousMonthSales = CALCULATE(SUM('TrackSales'[SalesAmt]), PREVIOUSMONTH('Calendar'[Date]))
VAR PreviousQuarterSales = CALCULATE(SUM('TrackSales'[SalesAmt]), PREVIOUSQUARTER('Calendar'[Date]))
VAR PreviousYearSales = CALCULATE(SUM('TrackSales'[SalesAmt]), PREVIOUSYEAR('Calendar'[Date]))

Var DynamicMeasure =
    if(SELECTEDVALUE (_tblDateDD[_DateDD Fields])="1",PreviousMonthSales,
        if(SELECTEDVALUE (_tblDateDD[_DateDD Fields])=2,PreviousQuarterSales,
        PreviousYearSales))
   
//  SWITCH (
//      SELECTEDVALUE (_tblDateDD[_DateDD Fields]),
//       1, PreviousMonthSales,
//       2, PreviousQuarterSales,
//       3, PreviousYearSales,
//      BLANK ()
//  )

Var ResultPct = Divide((CurrentMonthSales-DynamicMeasure),DynamicMeasure,0)
//Var ResultPct = Divide((CurrentMonthSales-PreviousYearSales),PreviousYearSales,0)
//Var ResultPct = Divide((CurrentMonthSales-PreviousQuarterSales),PreviousQuarterSales,0)
//Var ResultPct = Divide((CurrentMonthSales-PreviousYearSales),PreviousYearSales,0)

RETURN
   ResultPct
______________________________________________________________________________________________________________________
Any ideas on how I can make this work??

Thanks, Steven
2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi, @StevenT 

Regarding the issue you raised, my solution is as follows:

We suggest you use the _tblDateDD Order column as the parameter for the SELECTEDVALUE() function. As shown in the image below, the values corresponding to the _tblDateDD Fields column in the _tblDateDD table are the names of the columns you selected:

vlinyulumsft_0-1726194327966.png

Here is the modification to the judgment part, which we hope will be helpful to you:

 

 

SWITCH (
    TRUE (),
    SELECTEDVALUE ( '_tblDateDD'[_tblDateDD Order] ) = 1, "month",
    SELECTEDVALUE ( _tblDateDD[_tblDateDD Order] ) = 2, "quer",
    "year"
)

 

 

Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1726194391687.png

 

vlinyulumsft_2-1726194391687.png

 

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

This was a great help and thank you. I used your ideas and they worked great. Appreciated it!

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi, @StevenT 

Regarding the issue you raised, my solution is as follows:

We suggest you use the _tblDateDD Order column as the parameter for the SELECTEDVALUE() function. As shown in the image below, the values corresponding to the _tblDateDD Fields column in the _tblDateDD table are the names of the columns you selected:

vlinyulumsft_0-1726194327966.png

Here is the modification to the judgment part, which we hope will be helpful to you:

 

 

SWITCH (
    TRUE (),
    SELECTEDVALUE ( '_tblDateDD'[_tblDateDD Order] ) = 1, "month",
    SELECTEDVALUE ( _tblDateDD[_tblDateDD Order] ) = 2, "quer",
    "year"
)

 

 

Here's my final result, which I hope meets your requirements.

vlinyulumsft_1-1726194391687.png

 

vlinyulumsft_2-1726194391687.png

 

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

This was a great help and thank you. I used your ideas and they worked great. Appreciated it!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.