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

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.

Reply
Anonymous
Not applicable

Count ID's among hierarchies Paths in DAX

 

HI DATANUTS!!!

 

For sure this is a simple one.

 

I have an UNPIVOTED hierarchies table "[DIM_SET]". Some characteristics of this table are:

 

  • Children levels with multiple Fathers
  • Children could also be Fathers on upper levels

 

From wat we already now, DAX doesn’t support this type of hierarchies natively. Therefore, I build this “UNPIVOTED” hierarchies table in Access. I also added the “PATH” column to be able to use some DAX path functions.

 

SET.PNG

 

 

I’m trying to build a calculated column (L2_PATHS_COUNTROWS) to count how many times each L2 id is present among all paths.

 

Here I have an example for L2 id “1465660” :

 

L2_PATHS_COUNTROWS = COUNTROWS(FILTER(DIM_SET;PATHCONTAINS(DIM_SET[PATH];"1465660")))

 

The result is 8 and it is correct. Now I need to perform this calculation for each L2 id row.

 

THANKS IN ADVANCE!Smiley Wink

 

DIM_SET.TXT (LINK)

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

As the sharing link has expired.So I create a sample for your refernce. Please create a calculated column using the formula.

 

Column =
CALCULATE (
    COUNTROWS ( DIM_SET ),
    FILTER (
        ALLEXCEPT ( DIM_SET, DIM_SET[L2] ),
        PATHCONTAINS ( DIM_SET[Path], DIM_SET[L2] )
    )
)

Capture.PNG

 

Attched the pbix:)

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

5 REPLIES 5
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

Does that make sense? If so, kindly mark my answer as the solution to close the case please. Thanks in advance.

 

Regards,
Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
v-frfei-msft
Community Support
Community Support

Hi @Anonymous,

 

To create a calculated column as below. If it doesn't meet your requirement, kindly share your sample data to me,  if you don't have confidential data? Please upload your file to One Drive and share the link here.

 

Measure = CALCULATE(COUNT(DIM_SET[L2]),FILTER(DIM_SET,DIM_SET[L2]=1465660))

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Just updated the post with the file link. 

 

This formula is a MEASURE, I need a CALCULATED COLUMN that evaluates the column [PATH] for each row of [L2] counting in how many paths each [L2] Id is present.

 

Thank you.

Hi @Anonymous ,

 

As the sharing link has expired.So I create a sample for your refernce. Please create a calculated column using the formula.

 

Column =
CALCULATE (
    COUNTROWS ( DIM_SET ),
    FILTER (
        ALLEXCEPT ( DIM_SET, DIM_SET[L2] ),
        PATHCONTAINS ( DIM_SET[Path], DIM_SET[L2] )
    )
)

Capture.PNG

 

Attched the pbix:)

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

Thanks!!!

 

Short answer is yes, THE FORMULA IS CORRECT. Now, it is IMPOSSIBLE TO APPLY due to the performance.  On the example attached I see that you reduced the hierarchies to run the formula, but unfortunately for an 85k rows hierarchies table it is impossible to run it.  Instead I used a MEASURE for each level.

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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