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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
StevenT
Resolver I
Resolver I

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
v-linyulu-msft
Community Support
Community Support

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
v-linyulu-msft
Community Support
Community Support

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
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Top Solution Authors