Forum Discussion
Switch and calculate
- 6 years ago
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.