Forum Discussion
Using different calculations based on Column Value with switch/if loop
- 11 months ago
Hi rachelb123,
Thank you for clarification.
you can follow below approach.
create tool dimenssion table
ToolList =
DATATABLE(
"ToolName", STRING,
{
{"A"},
{"B"},
{"C"},
{"D"},
{"E"}
}
)Create Relationship
-
Relate
ToolList[ToolName]→UsageRateTable[ToolName]. -
Use ToolList[ToolName] in your matrix (instead of from
UsageRateTable).
Now write below measure
TotalWorkingDays = 63 // or dynamic from a calendar table later
Usage Rate (%) =
VAR _tool = SELECTEDVALUE('ToolList'[ToolName])
VAR _usageDays =
CALCULATE(
DISTINCTCOUNT('UsageRateTable'[UseDate]),
KEEPFILTERS(VALUES('ToolList'[ToolName]))
)
RETURN
SWITCH(
TRUE(),
_tool IN {"D","E"}, IF(_usageDays > 0, 1, 0),
DIVIDE(_usageDays, [TotalWorkingDays], 0)
) * 100 -
Hi rachelb123,
Just to be sure:
1 test usage, usage rate etc you mention in your post are just different attempato to solve the sane issue?
2 why the 64 at the denominator? Should not that be the nr of days of the quarter? Which might or not be 64 if we speaker about working days...
3 we are speaking about a measure or a column to create in DAX? I assume a measure but pls confirm
Finally, can you show an image of the visual you want to apply this thing to?
Thanks
If this helped, please consider giving kudos and mark as a solution
@me in replies or I'll lose your thread
Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Hi FBergamaschi,
1. Usage Days and Usage Rate are the original measure I used before Tool D and E were added to my dashboard. This worked because all the tools in the original table just used the basic formula stated above but now with this new addition there is a new way to calculate those. The Another Usage and Test Usage is my attempt at trying to include tool D and E into the calculation. They are both measures.
2. It is 64 because it excludes weekends and holidays.
3. Im very new at PowerBI and I dont know if having it as a measure/column is easier. Due to personal data I can't share a screenshot but this is what I want the matrix to look like-
| ToolName | Usage Rate (%) |
| A | 4.76% |
| B | 3.17% |
| C | 3.17% |
| D | 100% |
| E | 0% |