Forum Discussion

slothman's avatar
slothman
Microsoft Employee
4 years ago
Solved

Custom column or measure

Hello all,

 

I need help with a custom column or maybe a measure with the following logic:

Basically I have a table with categories and some values around them (Date column) where not all rows have data for that value column. You can think of category column as a hierarchy. What I want to achieve is to remove the rows that do not have any data but keep the parent nodes associated with the rows that have data. 

 

The logic for OutcomeWanted (OW) column/measure:

  • Check if Date column has a value, if it does then OW value is 1;
  • If OW = 1 assign 1 for it's immediate parents:
    • On row 3 below since the data appears on depth 2 its parent would be depth = 1 with MAX(SortOrder) since there could be other step-parent categories in that level with or without their own children. 
    • Once the parent is assigned iterate up and find parent's parent and evaluate to 1.
    • To better illustrate the logic, consider row with Child_2_3_2_1. 
      • It has data thus would evaluate to 1.
      • Since it is on depth 4 its parent would be with depth 3.
      • Since there are multiple categories with depth 3, the one with closest SortOrder should be assigned as its parent. So Child_2_3_2_1 has a SortOrder of 12, thus its parent must be row with Depth = 3 and Max(SortOrder) < CurrentChild(SortOrder), which is Child_2_3_2
      • Once Child_2_3_2 value is found its parent must be found with the same logic and assigned a value of 1. In this case it would be - Child_2_3.
      • So on and so forth untill the Parent category. 
  • If Date column is empty then assign 0.
CategoryDateSortOrderDepthOutcomeWanted
Parent 101
Child_1 211
Child_1_11/1/2020321
Child_1_2 420
Child_1_2_1 530
Child_2 611
Child_2_1 720
Child_2_2 820
Child_2_3 921
Child_2_3_1 1030
Child_2_3_2 1131
Child_2_3_2_12/2/20201241
Child_3 1310

 

The idea is to filter out based on OW column by showing only values with 1. So my final table would look like this:

CategoryDateSortOrderDepthOutcomeWanted
Parent 101
Child_1 211
Child_1_11/1/2020321
Child_2 611
Child_2_3 921
Child_2_3_2 1131
Child_2_3_2_12/2/20201241

 

Thanks for looking.

  • Hi,

    I am not sure if the below solution is the best way to approach, but please check the below picture and the attached pbix file. I tried to use PATH function and PATHITEM function to create the Outcome Wanted Calculated Column.

     

2 Replies

  • Hi,

    I am not sure if the below solution is the best way to approach, but please check the below picture and the attached pbix file. I tried to use PATH function and PATHITEM function to create the Outcome Wanted Calculated Column.

     

    • slothman's avatar
      slothman
      Microsoft Employee

      Thank you very much, this works great!