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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ngutc
Frequent Visitor

How to divide with a higher hierarchy group

Hello, 

 

I have these tables 

ngutc_3-1663136595186.png

 

Relationships

ngutc_1-1663136326405.png

 

I want is to group values by state and get these results. 

ngutc_4-1663136626672.png

Sure, I can just put the column into the required fields. But I want to use these values for a calculation. 

That would be Values in Facts Table 2 (F_state) divide with values in Facts table 1 group (F_city). 

For example first line in Facts Table 2 > The value with the first line in Facts table 1 group value.

calculation = 985/21368

 

I can't figure out how to do that with a DAX calculation. How to include the higher hierarchy in the calculation. Or if it's possible even.

 

calc =

var state = Calculate(SUM(F_state[Value]))

var city = Calculate(SUM(F_city[Value]))

return Divide(state/city)

 

Thank you. 

8 REPLIES 8
johnt75
Super User
Super User

I can think of a couple of options. You could link your states dimension table to the cities dimension, creating a snowflake schema. Or within your measure you could move the filters between dimensions using TREATAS. For example, within an iterator over cities you could do something like

var totalStateValue = CALCULATE( SUM(F_state[value]), TREATAS( VALUES(D_cities[state]), D_states[state]))
ngutc
Frequent Visitor

I can't make any changes in the model. That's why I'm trying to find out another way. 

I dont really understad the function TREATAS, how does it work in this situation. is the var totalStateValue my defined var state? Why this facts table if I'm trying to make change in the F_city table? 

TREATAS basically moves filters from one table to another. If you place a filter on the d_cities table for a specific city, e.g. in a table visual, that will also filter the values in the state column of d_cities table. You can then move that filter using TREATAS onto the d_states table, so any calculations you do on the F_state table will be filtered to just those rows related to the current state.

SQLBI have a video on TREATAS

ngutc
Frequent Visitor

Could show on my example the use of this function?

Put the below measure in a table visual with F_city[state] and Time[Year]

My Measure =
VAR cityValue =
    SUM ( F_city[Value] )
VAR stateValue =
    CALCULATE (
        SUM ( F_state[Value] ),
        TREATAS ( VALUES ( F_city[state] ), d_state[state] )
    )
RETURN
    DIVIDE ( stateValue, cityValue )
ngutc
Frequent Visitor

In the line TREATAS - 

( VALUES ( F_city[state] )

this value I don't have in my table (state column in not in the F_City table). How can it work¨,

use D_cities[state] instead

ngutc
Frequent Visitor

I don't think that's the solution I am looking for. Or it doesn't give me the results I want. mainly I dont understand why do I treat as the column state in D_cities and D-state column state? And should't the treatas be in the filter of the first variable, the cityValue? 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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