cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Anonymous
Not applicable

How to Improve my Dax/PowerQuery by avoiding hard-coding

Hi I have a table as follows

CustIDGroupIDCustTypeAmountGroup_CustType_Concat
11Intermediate101Intermediate 
11Intermediate 201Intermediate 
23Regular303Regular
23Regular 403Regular
23Regular 303Regular
32Intermediate 202Intermediate 
32Intermediate 602Intermediate  
44Rare404Rare 
51Rare30

1Rare 

I have concatinated GroupID and CustType to form unique combination.

I have then created what-if parameters for each CustType grouped by Group IDs as seen below.

jtan20_0-1652322727539.png

The goal is to sum 'Amount' for each unique value in Group_CustType_Concat and then multiply it by the respective what-if parameter value. In the current Dax I am creating  measures for each unique concatination to calculate the sum of amount and then multiply it by the respective parameter value. Another measure is created to add the results of the measures and group them by CustType to form a line chart. 

 

1Intermediate= Calculate(sum('Table'[amount]),'Table'[Group_CustType_Concat]=="1Intermediate") * '1Intermediate'[1Intermediate Value]

 

This is repeated for all unique Group_CustType_Concat and then added together using switch statement based on each custType.

 

Linechart = var type=IF(ISBLANK(SELECTEDVALUE('Table'[CustType])),TRUE,SELECTEDVALUE('Table'[CustType]))
return switch(type,
"Intermediate", [1Intermediate] + [2Intermediate] + [3Intermediate]
,"Regular", [1Regular] + [2Regular]+ [3Regular]

 

However, this is a very inefficient way, as there can be multiple Groups and CustTypes leading to a large number of combinations. Is there a more efficient way of doing this, so I don't have to hardcode Dax for each Group_CustType_Concat? Maybe some kind of loop that itterates through each Group_CustType_Concat and automatically calculates the sum and multiplies it by it's respective parameter? Maybe power query loop?

2 REPLIES 2
lbendlin
Super User
Super User

You may need to rethink your "what-if"  UX.  It is not possible to dynamically add/remove visuals in Power BI, and Small Multiples are not supported in "What-If"  scenarios.  Have you thought about using the filter panel instead?

Anonymous
Not applicable

Hi @lbendlin ,

 

The user viewing the dashboard needs to be able to change the values of the what-if slicers and that should only impact the sum of 'Amount' of that specific Group_CustType_Concat. So will not be able to use the filter panel for this. Also I am not trying to add or remove visuals, just trying to multiply the value of slicer to its respective concatinated group. For example this the measure to calculate the value when user changes the value of the 'Intermediate' slicer of Group 1:

 

1Intermediate= Calculate(sum('Table'[amount]),'Table'[Group_CustType_Concat]=="1Intermediate") * '1Intermediate'[1Intermediate Value]

 

This is repeated for all unique Group_CustType_Concat and then added together using switch statement based on each custType.

 

Linechart = var type=IF(ISBLANK(SELECTEDVALUE('Table'[CustType])),TRUE,SELECTEDVALUE('Table'[CustType]))
return switch(type,
"Intermediate", [1Intermediate] + [2Intermediate] + [3Intermediate]
,"Regular", [1Regular] + [2Regular]+ [3Regular]
 
Is there a simpler, more automated way of doing this?

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors