Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
thne123
Helper I
Helper I

"ALL" not working properly with sorting table

I'm encountering an error (or whatever I'm doing wrong...) where I have a calculation from fact Table A, for which I have a sorting table, that sorts the column rows into correct order. No problems here. We can call this ColumnX

 

I'm now trying to calculate a measure that should get all rows (per this ColumnX) divided by the total number of unique "SaleID" and then divided by the total number of days within this period. 

So far no worries, this measue works as intended when using the ColumnX from the regular table and I get the expected results. However, when I'm using the sorting column I get the wrong results. 

I've narrowed it down to it being the distinctcount of SaleID that end up wrong. Instead of it giving me the total number, it gives the total number per ColumnX. 

 

Here's my calculations: 

 

var _volume = COUNTROWS(TableA)

var _saleID = CALCULATE(DISTINCTCOUNT(TableA[ID]), ALL(TableA[ColumnX]), ALL(SortTable[ColumnY))

var _days = COUNT('Date'[Date])

var _average = DIVIDE(_volume,_saleID)

RETURN

DIVIDE(_average,_days)

 

For example:

var _saleID = CALCULATE(DISTINCTCOUNT(TableA[ID]), ALL(TableA[ColumnX]), ALL(SortColumn[ColumnY)) gives me the number 195 when using the main table. For all variatns of ColumnX

 

But, when using sort Table

I get 127 and 190

Which leads to the errors in my results. 

 

there's a 1-* relationship with single crossfilter direction between the main table and sorting table

I've tired making this go both ways but didn't help

 

Any idea on how to solve this? 

 

Edit: 

Table with sample data:

IDValueColumnXCountryDate
1110AAASWE2024-06-26
1120AAASWE2024-06-26
1130BBBSWE2024-06-26
2140BBBSWE2024-06-26
2100AAASWE2024-06-26
3200BBBNOR2024-06-26
3300AAANOR2024-06-26
4123AAASWE2024-06-26
1321BBBSWE2024-06-26
2222AAASWE2024-06-26

 

So for the example above: 

There are three unique IDs (1, 2 &4) for Sweden, and a total of 8 rows (for Sweden). 5 AAA rows, and 3 BBB rows. 

 

What I want is to then calculate:

for AAA column:

5/3/1 - 5 is for the five AAA rows, 3 is for three uniqe Sweden IDs, and 1 is for the number of days. 

for BBB column:

3/3/1 - 3 is for the three BBB rows, 3 is for three uniqe Sweden IDs, and 1 is for the number of days. 

 

What actually happens in Power BI is it instead calculates BBB column as:

3/2/1, because it only calculates the unique IDs for BBB columns. Instead of the total Sweden rows. 

 

1 ACCEPTED SOLUTION

Hi @thne123 ,

 

For the counting of individual IDs, you can try the following expression, and if there are still other problems, show your expected results:

vtianyichmsft_0-1720161355296.png

Measure = CALCULATE(DISTINCTCOUNT('Table'[ID]),ALLEXCEPT('Table','Table'[Country]))

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-tianyich-msft
Community Support
Community Support

Hi @thne123 ,

 

Any filters used? Try replacing ALL with ALLSELECTED.

 

Please feel free to correct me and provide more information if I have misunderstood you!

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

No filters for that column, but I tried and it didn't help

But thanks for the reply

Hi @thne123 ,

 

For the counting of individual IDs, you can try the following expression, and if there are still other problems, show your expected results:

vtianyichmsft_0-1720161355296.png

Measure = CALCULATE(DISTINCTCOUNT('Table'[ID]),ALLEXCEPT('Table','Table'[Country]))

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

@lbendlin 

Thanks!

I updated the original post with some more info and a table

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.