Skip to main content
cancel
Showing results for 
Search instead 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

Reply
Petr_M
Frequent Visitor

In a Matrix hierarchy, alter one node to a desired value

I have a matrix of sales in a hierarchy.

For the SubCategory x, I want to correct the value 16 to a more up-to-date 24. So I want to normalize that node and all its children by a factor 24/16. I think I'm able to do that part.

What I cannot figure out is adjusting the parent node and the total.

Any help would be highly appreciated.

 

Petr_M_0-1721390860773.png

 

 

1 ACCEPTED SOLUTION

Hi @Petr_M ,
Use the All function to ignore any filters that might have been applied during calculate 

denominator.

MeasureTotal =
VAR Denominator=CALCULATE([RWA Digit Actual],
FILTER(
ALL('digit_database'),
'digit_database'[NWU]= "B" && 'digit_database'[RWA_TYPE] = "X"
))
VAR Ratio = 24/Denominator
VAR TotalSales=SUMX(
SUMMARIZE(
digit_database,
digit_database[NWU],digit_database[RWA_TYPE],
"CalculatedValue",
IF(
SELECTEDVALUE(digit_database[NWU]) = "B",
SWITCH(digit_database[RWA_TYPE],"X",
SUMX(
FILTER(digit_database, digit_database[NWU] = "B" ),
[RWA Digit Actual] * Ratio
),[RWA Digit Actual]),
SUMX(
FILTER(digit_database, digit_database[NWU] <> "B"),
[RWA Digit Actual]
)
)
),
[CalculatedValue]
)
RETURN TotalSales

Another simple measure for your reference:
Measure =
VAR Denominator = CALCULATE(
   [RWA Digit Actual],
   FILTER(
       ALL('digit_database'),
       'digit_database'[NWU] = "B" && 'digit_database'[RWA_TYPE] = "X"
   )
)
VAR Ratio = 24 / Denominator
RETURN SUMX(
   ADDCOLUMNS(
       digit_database,
       "CalculatedValue",
       IF(
           [NWU] = "B" && [RWA_TYPE] = "X",
           [RWA Digit Actual] * Ratio,
           [RWA Digit Actual]
       )
   ),
   [CalculatedValue]
)
Result:
vyajiewanmsft_0-1722824191502.png

 

Best regards,

 

Joyce

 

If this post helps, then please considerAccept it as the solution to help the other members find it more quickly.

View solution in original post

10 REPLIES 10
v-yajiewan-msft
Community Support
Community Support

Hi @Petr_M,

For your requirements, please create a new calculated column as shown below:

 

Result =

VAR XSub =

CALCULATE(

    SUM('Table'[Sales]),

    FILTER(

        'Table',

        'Table'[SubCategory] = "X"

    )

)

VAR Divb = 24/XSub

VAR TotalSales =

IF(

    'Table'[SubCategory]= "X",

    'Table'[Sales] * Divb,

    'Table'[Sales]

)

RETURN

TotalSales

 

Result:

vyajiewanmsft_0-1721379245626.png

Best regards,

Joyce

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

 

Thank you @v-yajiewan-msft, this looks promising!

 

I only added the Category into identification of the node (as X may occur in other Categories as well) and it works perfectly.

 

However, my real life scenario works with a measure instead of Sales. I should have realized this was relevant to my question. I attempted to apply the proposed logic there but my calculated column returns nothing. So I assume it needs to be a measure as well which likely changes the context and would require a more complex solution :/.

Hi @Petr_M ,
Thank you for your reply and if possible, please upload your pbix example file so we can better test it for you.

Sorry for the delay in getting back to you! I had some busy days and had to strip my pbix of useless and confidential data.

 

On the right, there is your working example.

 

On the left, I'm attempting to replicate it in a more complex scenario. I have a digit_database fact table with three months. I choose the Actual month and want to display the original data (Act) and the Result which has the value of B/X node and its children normalized to given B/X sum.
I have different hierarchy level names (UNIT, RWA_TYPE, Segment1) and the hierarchy is defined outside of the fact table. So far, I was unable to figure this out.

 

Petr_M_0-1722337884483.png

 

Example.pbix 

Hi @Petr_M ,
Thank you for your sample pbix file, please try following measure to check the result:

 

MeasureTotal = 
VAR Denominator=CALCULATE([RWA Digit Actual],
    FILTER(
        'digit_database',
        'digit_database'[NWU]= "B" && 'digit_database'[RWA_TYPE] = "X"
    ))
VAR Ratio = 24/Denominator

VAR TotalSales=SUMX(
   SUMMARIZE(
       digit_database,
       digit_database[NWU],digit_database[RWA_TYPE],
       "CalculatedValue",
       IF(
           SELECTEDVALUE(digit_database[NWU]) = "B",
           SWITCH(digit_database[RWA_TYPE],"X",
           SUMX(
               FILTER(digit_database, digit_database[NWU] = "B"  ),
               [RWA Digit Actual] * Ratio
           ),[RWA Digit Actual]),
           SUMX(
               FILTER(digit_database, digit_database[NWU] <> "B"),
               [RWA Digit Actual]
           )
       )
   ),
   [CalculatedValue]
)
RETURN TotalSales

 

vyajiewanmsft_0-1722587861943.png

Best regards,

Joyce

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

Thank you, I really appreciate the time you put into this. That's some advanced stuff, I wouldn't be able to come up with.
At a first glance, however, the desired B/X sum seems to be 24.09 rather than 24.00. And the

[RWA Digit Actual] * 3

part looks a bit suspicious to me.

@Petr_M ,


Sorry for forgetting to change the test data, I've updated the above reply to the correct version.

Best regards,

 

Joyce

 

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

I tried to change the 3 to Denominator before, but this leads to everything under X being 24.

Petr_M_0-1722591667594.png

 

Hi @Petr_M ,
Use the All function to ignore any filters that might have been applied during calculate 

denominator.

MeasureTotal =
VAR Denominator=CALCULATE([RWA Digit Actual],
FILTER(
ALL('digit_database'),
'digit_database'[NWU]= "B" && 'digit_database'[RWA_TYPE] = "X"
))
VAR Ratio = 24/Denominator
VAR TotalSales=SUMX(
SUMMARIZE(
digit_database,
digit_database[NWU],digit_database[RWA_TYPE],
"CalculatedValue",
IF(
SELECTEDVALUE(digit_database[NWU]) = "B",
SWITCH(digit_database[RWA_TYPE],"X",
SUMX(
FILTER(digit_database, digit_database[NWU] = "B" ),
[RWA Digit Actual] * Ratio
),[RWA Digit Actual]),
SUMX(
FILTER(digit_database, digit_database[NWU] <> "B"),
[RWA Digit Actual]
)
)
),
[CalculatedValue]
)
RETURN TotalSales

Another simple measure for your reference:
Measure =
VAR Denominator = CALCULATE(
   [RWA Digit Actual],
   FILTER(
       ALL('digit_database'),
       'digit_database'[NWU] = "B" && 'digit_database'[RWA_TYPE] = "X"
   )
)
VAR Ratio = 24 / Denominator
RETURN SUMX(
   ADDCOLUMNS(
       digit_database,
       "CalculatedValue",
       IF(
           [NWU] = "B" && [RWA_TYPE] = "X",
           [RWA Digit Actual] * Ratio,
           [RWA Digit Actual]
       )
   ),
   [CalculatedValue]
)
Result:
vyajiewanmsft_0-1722824191502.png

 

Best regards,

 

Joyce

 

If this post helps, then please considerAccept it as the solution to help the other members find it more quickly.

Thank you so much, works perfectly!

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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