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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Sum by multiple Categories in a Measure in a visual with no said Category

Hello All,

 

Im looking for a meausure very similar to this https://community.fabric.microsoft.com/t5/Desktop/Sum-by-Category-Measure-in-a-visual-with-no-Catego... but with multiple categories.

 

I have a table with 4 columns, Shop Name, City, product and quantity.

 

Shop NameCity NameProductQTY
Fruit Galore Antwerp carrots137
Fruit FestLondoncarrots245
Fruit Fest Antwerp carrots453
Fruit Fest Antwerp Apple20

 

 

I want to show the total quantity in the network for every city/product combo related to the shop but not showing the city and product in visual. The resulting table would look like this.

 

Shop NameQty
Fruit Galore590
Fruit Fest855

 

Fruit Galore is 590 because total  Antwerp/Carrot-453+137

Fruit Fest is the sum of everything since it was every combination. 

 

Is there a dax measure that can do this?

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

I assume the semantic model looks like the below, and please check the below picture and the attached pbix file.

Jihwan_Kim_1-1708444183741.png

 

 

Jihwan_Kim_0-1708444161175.png

 

TREATAS function - DAX | Microsoft Learn

 

Expected result measure: =
VAR _t =
    SUMMARIZE ( Data, City[City Name], 'Product'[Product] )
VAR _filterfact =
    CALCULATETABLE (
        ALLSELECTED ( Data ),
        TREATAS ( _t, Data[City Name], Data[Product] )
    )
RETURN
    IF ( HASONEVALUE ( Shop[Shop Name] ), SUMX ( _filterfact, Data[QTY] ) )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

I assume the semantic model looks like the below, and please check the below picture and the attached pbix file.

Jihwan_Kim_1-1708444183741.png

 

 

Jihwan_Kim_0-1708444161175.png

 

TREATAS function - DAX | Microsoft Learn

 

Expected result measure: =
VAR _t =
    SUMMARIZE ( Data, City[City Name], 'Product'[Product] )
VAR _filterfact =
    CALCULATETABLE (
        ALLSELECTED ( Data ),
        TREATAS ( _t, Data[City Name], Data[Product] )
    )
RETURN
    IF ( HASONEVALUE ( Shop[Shop Name] ), SUMX ( _filterfact, Data[QTY] ) )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Thank you, the output is what im looking for but im using a different data set with a similar semantic model. I have never really used the virtual table before, can you explain the logic and purpose of using the variables _t  and _filterfact? I want to recreate the measure with tables I'm using. 

 

_t is creating every city product combinantion in a table correct? 

 

_filterfact is recreating the 'data' table virtually to be used in the calculate function?

Hi,

Thank you for your message, and you are correct.

 

Please check the comments down below.

 

Expected result measure: =
VAR _t =       //  it shows all the combination of city and product of each row (shop name).
    SUMMARIZE ( Data, City[City Name], 'Product'[Product] )

VAR _filterfact =          // from all fact table ( remove filter context), apply the combination of city and product that are generated from above.
    CALCULATETABLE (
        ALLSELECTED ( Data ),
        TREATAS ( _t, Data[City Name], Data[Product] )
    )

RETURN
    IF ( HASONEVALUE ( Shop[Shop Name] ), SUMX ( _filterfact, Data[QTY] ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

follow-up question as some of my requirements have changed. How would I do this as a calculated column?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.