Forum Discussion

witbi's avatar
witbi
Icon for Helper I rankHelper I
5 years ago
Solved

Extract parent for child based on ordered list reference

Hello everyone,

 

I have a table that has an ordered list reference which I would like to convert into a flat hierarchy to use in filters. However, I'm stuck on how to extract the parent for each child. If anyone has ideas on how this could be easily done in DAX that would be most helpful.

 

Many thanks

 

Example of the starting table

RefDescriptionEvent
1AndyA
1.1GreenA
1.2BlueA
1.2.1WaterA
2BillA
2.1YellowA
2.1.1WoodA
2.1.2PaperA
2.2OrangeA
3ChrisB
3.1PurpleB
4DaveB
4.1BlackB
4.2WhiteB
1AndyC
1.2BlueC
1.2.1WaterC
3ChrisC
3.1PurpleC

 

Target flat structure

Ordered ListNameEventLevel 1Level 2Level 3
1AndyAAndy  
1.1GreenAAndyGreen 
1.2BlueAAndyBlue 
1.2.1WaterAAndyBlueWater
2BillABill  
2.1YellowABillYellow 
2.1.1WoodABillYellowWood
2.1.2PaperABillYellowPaper
2.2OrangeABillOrange 
3ChrisBChris  
3.1PurpleBChrisPurple 
4DaveBDave  
4.1BlackBDaveBlack 
4.2WhiteBDaveWhite 
1AndyCAndy  
1.2BlueCAndyBlue 
1.2.1WaterCAndyBlueWater
3ChrisCChris  
3.1PurpleCChrisPurple 

7 Replies

  • Create your lists in Power Query, using pipe "|" as the concatenator. Then in DAX you can use PATHITEM etc functions.

    • witbi's avatar
      witbi
      Icon for Helper I rankHelper I

      Thanks wdx223_Daniel,
      This looks to be an elegant solution but I can't seem to get the syntax right? Would you possibly be able to upload the sample?

      Name =
      VAR _m=MAX('DimLevels'[Value])
      VAR _p=SUBSTITUTE(MAX('Table'[Ref]),".","|")
      VAR _e=MAX('Table'[Event])
      VAR _ref=CONCATENATEX(FILTER(ALL('DimLevels'),'DimLevels'[Value]<= _m), PATHITEM(_p,'DimLevels'[Value]),".")

      RETURN
      IF(_m <= PATHLENGTH(_p),LOOKUPVALUE('Table'[Description],'Table'[Ref],_ref,'Table'[Event],_e),)