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 am new to PowerBI. I hope someone can help as I've been struggling for a few hours.
Let's say I have the below data.
date | event_label | trials associated with events | trials per day |
2023-01-01 | label 1 | 5 | 120 |
2023-01-01 | label 2 | 15 | 120 |
2023-01-01 | label 3 | 9 | 120 |
2023-01-02 | label 2 | 6 | 116 |
2023-01-02 | label 4 | 13 | 116 |
In a table view I am pulling in the "date", "trials associated with events" and "trials per day" columns. PowerBI correctly decides to sum the column "trials associated with events".
Problem1 : It then incorrectly decides to sum the "trials per day" column. Not it's fault. This column is the result of an SQL window function that just outputs the number of trials as reported by internal systems per day, hence the same number is repeated for every row with the same date.
This was not so hard to circumvente at the row level. I can either take the average or min or max or median. I can even use the below dax function code to actually grab just the value in the first row in the group.
First value = FIRSTNONBLANK(
Table[trials per day]
, [trials per day] <> BLANK()
)
So many options. I am so smart.
Problem 2 (which I can't solve because I am not so smart): Where all of the above options fail is when it comes to the "Total" values at the bottom of the table view. I am looking for a way to get a total that is the sum of all those first values from the column "trials per day" when grouping by date by "date".
So basically the below table is what I want to see in the view.
date | trials associated with events | trials per day | |
2023-01-01 | 29 | 120 | |
2023-01-02 | 19 | 116 | |
Totals | 48 | 236 |
I've been playing around with context manipulation but no luck.
Kind regards,
Cristian
Solved! Go to Solution.
Please see this video for how to get your expected total.
(2) Power BI - Tales from the front #01 - Getting the Right Total - YouTube
In your case, you likely need something like
NewMeaure = SUMX(VALUES(Table[Date]), [Trials associated with events])
Pat
Hi @cristiancapsuna,
Glad that helped. I'm not sure I understand the second issue- can you please explain what is happening now and what you are looking for?
Please see this video for how to get your expected total.
(2) Power BI - Tales from the front #01 - Getting the Right Total - YouTube
In your case, you likely need something like
NewMeaure = SUMX(VALUES(Table[Date]), [Trials associated with events])
Pat
Hi Pat. Thank you for your help. I modified it to the below and it worked. And it workes by itself without separating the row level from the total level.
Hi @djurecicK2 ,
Thank you for your response. That gives me a very nice way to separate the row level from the total overview. I am still stuck on how to apply the date group by context on the contextless Total. Would you be able to help me with that? If you edit your last message then I can mark it as having solved the entire problem.
Hi @cristiancapsuna ,
You can use IF(HASONEVALUE(tablename[date]) to determine if the row is a normal row with a date or a total row. If it has one value it is a normal row, if it doesn't it is a total row.
https://mitchellpearson.com/2018/05/18/unexpected-totals-in-dax-part-1/
Hi @djurecicK2 . Thanks for teaching me about the HASONEVALUE function. I will keep that in the back pocket. On this ocassion it seems that what Pat suggested handles the context correctly by itself so I'll go with that as it's simpler.
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 |
---|---|
109 | |
98 | |
77 | |
66 | |
54 |
User | Count |
---|---|
144 | |
104 | |
100 | |
86 | |
64 |