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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX: Accessing values of parents? (using junction table)

Hi, sorry trying to make this work and decompressed my real-life problem into this simple case:

 

 

IjTGe.pngcjM5k.pngkDBjh.png 

 

Essentially, I want to add a measure column to the `stores` table.
This `measure` column would find all the parents the child has and combine (sum or average) all its `some_value`'s.

I was trying to do it in a way like this

 

Measure = CALCULATE(SUM(stores[some_value]), FILTER(ALL(stores), 'stores'[store_child_and_parent] = VALUES(store_relationship[store_parent])))

 

but I feel lost. Cat Sad

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks, @Zubair_Muhammad!

 

Your solution kickstarted my brain and eventually I managed to figure out what I wanted!

measure = CALCULATE(
    SUM(
        'stores'[some_value]
    ),
    FILTER(
        ALL('stores'),
        'stores'[store_child_and_parent] in VALUES('store_relationship'[store_parent])
    )
)

 

But then, because some_value (albeit not in this example but in my real world one) is actually a measure I was looking to get an average grouped by the child store.... was about to give up and ask here but eventually I did it!!!

 

measure = CALCULATE(
    AVERAGEX(
        'stores',
        'stores'[some_value]
    ),
    FILTER(
        ALL('stores'),
        'stores'[store_child_and_parent] in VALUES('store_relationship'[store_parent])
    )
)

I'm the happiest DAX newbie in the world right now!

Still trying to figure out this whole DAX thing, it seems very powerful but not as obvious.

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

So, in the data from your example, 5 would get a value of 666 (if summing) and 4 would be 111, correct?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Ah, sorry didn't mention it in the post. You are correct! 666 and 111!

@Anonymous

 

Please try this MEASURE

 

Measure =
VAR parents =
    VALUES ( store_relationship[store_parent] )
VAR result =
    CALCULATE (
        SUM ( Stores[some_value] ),
        FILTER ( ALL ( Stores ), Stores[store_child_and_parent] IN parents )
    )
RETURN
    IF ( ISBLANK ( result ), 0, result )

Regards
Zubair

Please try my custom visuals

@Anonymous

 

Please see attached file with your sample data

 

DAXparents.png


Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Thanks, @Zubair_Muhammad!

 

Your solution kickstarted my brain and eventually I managed to figure out what I wanted!

measure = CALCULATE(
    SUM(
        'stores'[some_value]
    ),
    FILTER(
        ALL('stores'),
        'stores'[store_child_and_parent] in VALUES('store_relationship'[store_parent])
    )
)

 

But then, because some_value (albeit not in this example but in my real world one) is actually a measure I was looking to get an average grouped by the child store.... was about to give up and ask here but eventually I did it!!!

 

measure = CALCULATE(
    AVERAGEX(
        'stores',
        'stores'[some_value]
    ),
    FILTER(
        ALL('stores'),
        'stores'[store_child_and_parent] in VALUES('store_relationship'[store_parent])
    )
)

I'm the happiest DAX newbie in the world right now!

Still trying to figure out this whole DAX thing, it seems very powerful but not as obvious.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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