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
JKamHC
Frequent Visitor

Measure using Switch True within Matrix not filtering appropriately

Not sure what's going on with this. For context, I have a filter on a date reference table limiting the data to 2020, 2021, 2022 data. Within the matrix, if I use the below Switch statement (which simply grabs a measure based on a slicer) the filtered years appear in the matrix. If I swap out the switch measure for the measure it's grabbing ([Sum Net Rev Attrib]) I get the desired result where the filtered years do not display. Both measures within the switch statements are standard SUM ( some column ), nothing fancy. The only change is one the measure is directly placed in the matrix values and produces the desired result but, when the same measure is being called coming through SWITCH TRUE the filter does not apply to the matrix correctly any longer.

 

Any thoughts on how to use the switch logic and have the filtered years not display?

 

For consideration:

  • I've used a secondary measure of ISBLANK ( [Outcomes Selection] ) to check the filtered columns that are displaying (2018 and 2019) which returns FALSE for all rows. This means within the matrix the filtered columns are not actually blank so I can't add a filter to the visual an have the columns removed since they are not blank.
  • I've tried the date filtering on both the page and the visual with the same results.
  • I've removed the TRUE() aspect within the SWITCH statement and had the same result.

 

Outcomes Selection =
VAR vOutcomeSelection = SELECTEDVALUE( '_MeasuresTable'[MeasureID], 0 )

 

RETURN
SWITCH(
TRUE(),
vOutcomeSelection = 100, FORMAT( [SUM Net Rev Raw], "$#,##0" ),
vOutcomeSelection = 101, FORMAT( [Sum Net Rev Attrib], "$#,##0" ),
"error"
)

 

With Switch:

With SwitchWith Switch

 

Without Switch:

Without SwitchWithout Switch

 

 
1 ACCEPTED SOLUTION

Hey there, thanks for the reply. I believe I figured this out this morning. I'm actually using the new parameter feature for the columns but did not explain that. Normally I would take that approach however, I've run into issues with the new feature when trying to have other measures switch based on what parameter is selected. 

 

This table is getting built out more with Prior Period and % change from prior period throughout the date hierarchy. Where I've run into issues and haven't seemed to figure out is how to setup my prior period measure to use the measure for whatever is currently selected within the parameter. So, for this example I have two options I could setup the parameter for (Attributed Revenue and Base Revenue). If I were just displaying those two values the parameter method would be easy. However, if I'm trying to calculate the prior period based on whichever item is selected within the parameter I haven't figured out a way to do that within DAX yet. I'm probably missing something obvious but I haven't been able to get it to work.

 

For this problem, the issue was actually using the default calendar hierarchy auto created by PowerBI. When I created a custom Hierarchy using the fields within my date reference table everything worked as intended with the different date filters using that switch statement.  

View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@JKamHC,

 

Is the objective to enable dynamic measure selection (i.e. the ability to toggle between [SUM Net Rev Raw] and [Sum Net Rev Attrib])? If so, there's a simpler approach using the new feature Field Parameters:

 

https://docs.microsoft.com/en-us/power-bi/create-reports/power-bi-field-parameters 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hey there, thanks for the reply. I believe I figured this out this morning. I'm actually using the new parameter feature for the columns but did not explain that. Normally I would take that approach however, I've run into issues with the new feature when trying to have other measures switch based on what parameter is selected. 

 

This table is getting built out more with Prior Period and % change from prior period throughout the date hierarchy. Where I've run into issues and haven't seemed to figure out is how to setup my prior period measure to use the measure for whatever is currently selected within the parameter. So, for this example I have two options I could setup the parameter for (Attributed Revenue and Base Revenue). If I were just displaying those two values the parameter method would be easy. However, if I'm trying to calculate the prior period based on whichever item is selected within the parameter I haven't figured out a way to do that within DAX yet. I'm probably missing something obvious but I haven't been able to get it to work.

 

For this problem, the issue was actually using the default calendar hierarchy auto created by PowerBI. When I created a custom Hierarchy using the fields within my date reference table everything worked as intended with the different date filters using that switch statement.  

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.