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.
Hi everyone,
I am trying to calculate percentage total no of transactions occured across filters.
My data is as follows,
Hour | Weekname | Count_loading_col | Total_loading | Total teus | Location_name | Column |
41 | 20WK24 | 0 | 0 | 90 | 0 | |
4 | 20WK24 | 80 | ND | |||
20WK24 | a | ND | ||||
8 | 20WK24 | 0 | 0 | 90 | 0 | |
71 | 20WK24 | 0 | 0 | 80 | b | 0 |
3 | 20WK24 | 22 | 1 | 90 | 1 | |
21 | 20WK25 | 0 | 0 | 90 | 0 | |
13 | 20WK25 | 0 | 0 | 88 | 0 | |
20WK25 | ND | |||||
4 | 20WK25 | c | ND | |||
41 | 20WK25 | 0 | 0 | d | 0 | |
7 | 20WK25 | 0 | 0 | 0 | ||
20WK25 | ND | |||||
47 | 20WK25 | 0 | 0 | 80 | b | 0 |
11 | 20WK25 | 0 | 0 | 80 | 0 | |
23 | 20WK25 | 0 | 0 | e | 0 | |
9 | 20WK25 | 0 | 0 | b | 0 | |
15 | 20WK25 | 0 | 0 | a | 0 | |
8 | 20WK25 | 0 | 0 | a | 0 | |
2 | 20WK25 | 22 | 1 | 1 | ||
5 | 20WK25 | 0 | 0 | 0 | ||
20WK25 | ND | |||||
50 | 20WK25 | 0 | 0 | 90 | 0 | |
16 | 20WK25 | 0 | 0 | a | 0 | |
6 | 20WK25 | 0 | 0 | c | 0 | |
6 | 20WK25 | 0 | 0 | a | 0 |
I want to calculate as follows,
For a week across different locations what is percentage.
1. First need to filter across location and weekname.
2. Check for overall count for that week and location. (Ex. b location has 10 counts in week 20WK25).
3. Have a condition with Hour <4, check for that particular condition in that week. (Ex. b location has passed 4 counts in week 20WK25).
4. Calculate percentage which step 3/step2.
How can I go about this?
Switch and calculate in measure is not working, if I do in calculated columns how can I go about it?
Thanks
Solved! Go to Solution.
Hi, @Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a measure as below.
Percenatage =
var _table = ALLSELECTED('Table')
var tab =
SUMMARIZE(
'Table',
'Table'[Weekname],
"Result",
var _weekname = [Weekname]
var newtab =
SUMMARIZE(
_table,
'Table'[Hour],
'Table'[Weekname],
'Table'[Location_name],
"flag",
IF(
'Table'[Hour]>4&&[Location_name]<>"",
1,0
)
)
return
DIVIDE(
CALCULATE(
DISTINCTCOUNT('Table'[Location_name]),
FILTER(
newtab,
'Table'[Weekname]=_weekname&&
[flag]=1
)
),
COUNTROWS(
FILTER(
newtab,
[Weekname]=_weekname&&
[Location_name]<>""
)
)
)
)
return
SUMX(
tab,
[Result]
)
The overall count for '20WK25' with a location is 10. The distinct count location name with criteria of hour>4 for '20WK25' is 5. Here is the result.
If I misunderstand your thoughts, please show us your expected result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a measure as below.
Percenatage =
var _table = ALLSELECTED('Table')
var tab =
SUMMARIZE(
'Table',
'Table'[Weekname],
"Result",
var _weekname = [Weekname]
var newtab =
SUMMARIZE(
_table,
'Table'[Hour],
'Table'[Weekname],
'Table'[Location_name],
"flag",
IF(
'Table'[Hour]>4&&[Location_name]<>"",
1,0
)
)
return
DIVIDE(
CALCULATE(
DISTINCTCOUNT('Table'[Location_name]),
FILTER(
newtab,
'Table'[Weekname]=_weekname&&
[flag]=1
)
),
COUNTROWS(
FILTER(
newtab,
[Weekname]=_weekname&&
[Location_name]<>""
)
)
)
)
return
SUMX(
tab,
[Result]
)
The overall count for '20WK25' with a location is 10. The distinct count location name with criteria of hour>4 for '20WK25' is 5. Here is the result.
If I misunderstand your thoughts, please show us your expected result.
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks @v-alq-msft . It was very helpful.
Done following calculations,
Step 1: created calculated column for hour.
@Anonymous , not very clear.
do you wow comparision ?
@amitchandak, Thanks for your reply, I am not looking for that comparison, I am looking for calculation.
I want to calculate percentage across location and across weeks. Ex. 20Wk25 location a achieved 30% like that by using DAX.
My steps are
1. Calculate Overall count across week and location(Ex. location b has 10 counts in week 25)
2. Calculate count with criteria of hour>4. (Ex. location b has passed 5 transactions(counts) in week 25)
3. calculate percentage(Step2/Step1) for each location and week. My DAX should be dynamic so that I dont need to check for weeks everytime.
So I tried for started doing step 3,
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
97 | |
96 | |
81 | |
74 | |
66 |
User | Count |
---|---|
126 | |
106 | |
105 | |
86 | |
72 |