Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi all,
I'm looking to get feedback on how I could acheive something similiar to a loop in DAX. I'm familiar with SWITCH and already using it (as you can see in the code below) however I'm faced with a significant scaling issue.
Per the code below I have three variables I need to evaluate for each condition to use a specific measure when that condition is met. There are 8 Sites, 6 Care Settings and each Care Setting has about 6 Categories (varies). So the current code sample is a smaller representation of something I need to scale significantly. Does anyone have suggestions on how I can dyanimcally iterate through the various comibinations or make use of more variables? Can I "create" a measure name based on variables? Other suggestions on all the conditions? If I was in C# or VB (not that I'm terribly profecient in either) I would use a loop to iterate through all the possible combinations and set the values properly.
Thoughts? Ideas? Trying to avoid a huge chunk of time writing a ton of repetitive code and the associated risk of making mistake(s).
Thanks!
% of Prog =
//variables for Columns
VAR CareSetting = MAX(prog_SiteProgram[prog_CareSettings.ServiceName])
VAR Category = MAX(prog_SiteProgram[prog_Categories.Name])
VAR Site = MAX(prog_SiteProgram[site_Sites.Abbreviated Name])
RETURN
SWITCH(
TRUE(),
CareSetting = "Acute Care" &&
Category = "Ambulatory" &&
Site = "GH",
[1.acu.a Value],
CareSetting = "Acute Care" &&
Category = "Inpatient" &&
Site = "GH",
[1.acu.i.%Prog],
CareSetting = "Acute Care" &&
Category = "Diagnostic" &&
Site = "GH",
[1.acu.d Value],
CareSetting = "Acute Care" &&
Category = "Treatment" &&
Site = "GH",
[1.acu.t Value],
CareSetting = "Administration" &&
Category = "Administration" &&
Site = "GH",
[1.admin Value],
BLANK()
)
Note, in case you're wondering "what the heck is this guy doing", the reason for what appear to be individual measures being applied to each row is the values are coming from indiviual WhatIf Parameters driven by "sliders" (slicers). So I have to tabulate all those unique values into a table so I can do further calculates based on the values set by the end user. I've proven out the majority of my infrastructure, but now I've looped back to scaling this out for the whole data model.
Refer to https://gregdeckler.com
@Greg_Deckler I'll take a look.
Does this mean you don't think I'm crazy, and there is a ray of hope?
Thanks,
-R
Hi @Greg_Deckler ,
Read through the blog post, generally makes sense without going and writing my own.
In thinking my situtation through though, I think I'm still stuck...
Using your approach here is how I think it would play out for me.
I have a table with an index that by virtue of its columns defines all the various combinations (rows). Using your approach we would iterate through each row, and for each row I could use the MAXX formulas to find the values for those rows (my conditions). Great, now I could say "do X" for this particular condition, and I didn't have to spell out each condition. Where I think I'm going to get stuck though is the "do X" I want is to assign a specific measure to that condition and I don't see a way to (through logic) specifiy use this Measure for this condition unlees there is a clever way to just add a bunch of measures to a single column in table and index it, then I would be able to say for Index 1 of my first table, match that to Index 1 of the Measure Table. The whole intent of this execise is to align each unique measure to the particular row so that I can then proceed to carry out more "normal" tabular calculations like sums, divides, multiplies, etc.
Am I missing something?
@Anonymous - It's very difficult to say how this would work in your situation without seeing 1. Sample data and 2. Expected output from sample data.
Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
Hello all,
A sanitized version of my PBIX and data model are here (the link expires on 4/12, I'll try to renew it, if not post in this thread: https://stantec-my.sharepoint.com/:f:/p/robert_manna/EnbE-K84tNlHofWg91AVbvsBTw4VIFOkFbkvxbbaZK9Osg?... ), screen shot with mark-ups below.
Giving this a tickle now that the Holiday weekend is wrapped up for most (see post above). I was hoping @Greg_Deckler might have some additional feedback or thoughts.
Thanks for looking!
Yeah.... I know. Creating a sample model will take some effort, but I will undertake that as soon as I get through my deadline today. I do appreciate your quick responses and assistance.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
7 | |
6 | |
5 |
User | Count |
---|---|
20 | |
14 | |
10 | |
9 | |
6 |