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.
Hello, I need to create a power bi metrics table to display as below. I have day of month column. in this example i only have for 12 days, but my Day of Month is from 01st day of the month to the last day of the month based on the month filter.
I need to show Yes , No and Leave and Total to only be Sum of Yes, Appreciate any help. Yes , No, Leave can either be shown by 1,0, 2
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Total Yes |
Employee A | Leave | Leave | Leave | Yes | Yes | Yes | Yes | Yes | Yes | No | No | No | 6 |
Employee B | No | No | No | No | No | No | Yes | Yes | Yes | Yes | Yes | Leave | 5 |
Employee C | Yes | Yes | Yes | Yes | Yes | Leave | Leave | Leave | Leave | Yes | Yes | Yes | 8 |
Solved! Go to Solution.
Ok great, that means my original measure would be the correct measure. That is always handled in the "SELECTEDVALUE" part of the measure. The countrows part is just to calculate the total. I suspect you want this:
M_MetricsMeasure = IF(
COUNTROWS('Table_by_calendar_Cat1') = 1,
SELECTEDVALUE('Table_by_calendar_Cat1'[Result]),
FORMAT(
CALCULATE(
COUNTROWS('Table_by_calendar_Cat1'),
'Table_by_calendar_Cat1'[Result] = "Yes"
),
"0")
)
which will have an output like this:
We can add a +0 in the count. This can have unintended consequences as it will come up with zero for every possible outcome.
M_MetricsMeasure = IF(
COUNTROWS('Table_by_calendar_Cat1') = 1,
SELECTEDVALUE('Table_by_calendar_Cat1'[Result]),
FORMAT(
CALCULATE(
COUNTROWS('Table_by_calendar_Cat1'),
'Table_by_calendar_Cat1'[Result] = "Yes"
) + 0,
"0")
)
To get around this, if its a problem, we can add some additional checks to divert the outcome to blank() in the contexts where you are getting 0 whenever you don't want it.
Hello Ross,
What has me confused in your measure is the setting Leave as 2. This seems to indicate that you want Leave to count as a twice as much compared to Yes. So a table of "Employee A: Yes, No, No, Leave" would equal 3?
I'm also confused why you need the all except?
I'd go with:
M_MetrcisMeasure = IF(
COUNTROWS('Table_by_calendar_Cat1') = 1,
SELECTEDVALUE('Table_by_calendar_Cat1'[Result]),
FORMAT(
CALCULATE(
COUNTROWS('Table_by_calendar_Cat1'),
'Table_by_calendar_Cat1'[Result] = "Yes"
) + (CALCULATE(
COUNTROWS('Table_by_calendar_Cat1'),
'Table_by_calendar_Cat1'[Result] = "Leave"
) * 2),
"0")
)
Sorry for the confusion, I needed to show leave days in my metrics table so i created a Leave = 2, however i dont need the sum of Leave, the total to only be Sum of "Yes"
Ok great, that means my original measure would be the correct measure. That is always handled in the "SELECTEDVALUE" part of the measure. The countrows part is just to calculate the total. I suspect you want this:
M_MetricsMeasure = IF(
COUNTROWS('Table_by_calendar_Cat1') = 1,
SELECTEDVALUE('Table_by_calendar_Cat1'[Result]),
FORMAT(
CALCULATE(
COUNTROWS('Table_by_calendar_Cat1'),
'Table_by_calendar_Cat1'[Result] = "Yes"
),
"0")
)
which will have an output like this:
One more help please, how do i show 0 when there is no "Yes" for an employee, Example in your table, Employee B Total to show 0
We can add a +0 in the count. This can have unintended consequences as it will come up with zero for every possible outcome.
M_MetricsMeasure = IF(
COUNTROWS('Table_by_calendar_Cat1') = 1,
SELECTEDVALUE('Table_by_calendar_Cat1'[Result]),
FORMAT(
CALCULATE(
COUNTROWS('Table_by_calendar_Cat1'),
'Table_by_calendar_Cat1'[Result] = "Yes"
) + 0,
"0")
)
To get around this, if its a problem, we can add some additional checks to divert the outcome to blank() in the contexts where you are getting 0 whenever you don't want it.
OMG, Perfect , it worked a treat,
Thank you so much Ross.
I would create a measure that checks if its running under a single answer context and if it is, provides the answer. If its not, it does a count of the records within the multianswer context that equal yes. Here is a quite example bit of code that you'll need to edit and test.
Your Measure = IF(
COUNTROWS('YourTable') = 1,
SELECTEDVALUE('YourTable'[YourField]),
FORMAT(CALCULATE(
COUNTROWS('YourTable'),
'YourTable'[YourField] = "Yes"
), "0")
)
Thanks Ross, However m the Total per each employee is showing 0, it does not ad up the number of yes.. Appreciate any help
First lets check that this measure has been applied correctly. I'm assuming:
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 |
---|---|
58 | |
19 | |
19 | |
18 | |
9 |