cancel
Showing results 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

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:

 ID Value ColumnX Country Date 1 110 AAA SWE 2024-06-26 1 120 AAA SWE 2024-06-26 1 130 BBB SWE 2024-06-26 2 140 BBB SWE 2024-06-26 2 100 AAA SWE 2024-06-26 3 200 BBB NOR 2024-06-26 3 300 AAA NOR 2024-06-26 4 123 AAA SWE 2024-06-26 1 321 BBB SWE 2024-06-26 2 222 AAA SWE 2024-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
Community Support

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:

``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.

5 REPLIES 5
Community Support

Hi @thne123 ,

Any filters used? Try replacing ALL with ALLSELECTED.

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.

Helper I

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

Community Support

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:

``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.

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.

Helper I

Thanks!

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