cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
RudnevOleg Frequent Visitor
Frequent Visitor

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

Accepted Solutions
Community Support Team
Community Support Team

Re: Count ID's among hierarchies Paths in DAX

Hi @RudnevOleg ,

 

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 pbixSmiley Happy

 

Regards,

Frank

Community Support Team _ Frank
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 Team
Community Support Team

Re: Count ID's among hierarchies Paths in DAX

Hi @RudnevOleg,

 

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 other members find it more quickly.
RudnevOleg Frequent Visitor
Frequent Visitor

Re: Count ID's among hierarchies Paths in DAX

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.

Community Support Team
Community Support Team

Re: Count ID's among hierarchies Paths in DAX

Hi @RudnevOleg ,

 

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 pbixSmiley Happy

 

Regards,

Frank

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

Re: Count ID's among hierarchies Paths in DAX

Hi @RudnevOleg ,

 

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 other members find it more quickly.
RudnevOleg Frequent Visitor
Frequent Visitor

Re: Count ID's among hierarchies Paths in DAX

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.