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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
RichOB
Helper IV
Helper IV

Need help with measure for combining data from 2 tables

Hi, I'm looking for help with a measure please.

 

I need the measure that grabs the amounts from only Cleaning, Training, Utilities...and the filtering part of the measure to use the Category_name, not the GL_code. So in a Card it would display Combined_Amount 330.

 

Table 1: Cat_Codes

GL_codeCategory_name
GL1Cleaning
GL2Cleaning 
GL3Cleaning 
GL4Utilities
GL5Utilities
GL6Utilities
GL7Utilities
GL8Training
GL9Training
GL10Salaries


Table 2: Amount_Table

 

GL_codeBalance
GL1£45
GL2£45
GL3£50
GL4£25
GL5£20
GL6£15
GL7£35
GL8£45
GL9£50
GL10£200

 

Combined_Amount =
CALCULATE(
    SUM(Amount_Table[Balance]),
    Cat_codes [Category_name] IN {Utilities, Training, Cleaning}
)
 

I need the measures to be somewhat like the above (but correct) where the amounts are drawn from the balance and the categories are drawn from what category names are input, please. 

 

For more context, I need the category (not GL_code) in the measure, as in my real-life scenario there are thousands of GL_codes and only a handful of Category_names which makes it more realistic to create. Also, I need this as a measure not to just unselect Salaries from the Filter pane.

 

Thanks for your help

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @RichOB ,

 

If the filter from the ‘Cat_Codes’ table can be passed to the ‘Amount_Table’ table, then there seems to be no problem with your code, you just need to add double quotes to the text values in it:

vcgaomsft_0-1725849709478.png

IN {"Utilities", "Training", "Cleaning"}

Or you want that part of the result to be dynamic:

Combined_Amount = 
CALCULATE(
    SUM(Amount_Table[Balance])
)

vcgaomsft_1-1725849760677.png

Either there is no relationship between the two tables, or the filter cannot be passed.

vcgaomsft_2-1725849900347.png

Fixed:

Combined_Amount = 
CALCULATE(
    SUM(Amount_Table[Balance]),
    TREATAS(CALCULATETABLE(VALUES('Cat_Codes'[GL_code]),'Cat_Codes'[Category_name] IN {"Utilities", "Training", "Cleaning"}),'Amount_Table'[GL_code])
)

  Dynamic:

Combined_Amount = 
CALCULATE(
    SUM(Amount_Table[Balance]),
    TREATAS(VALUES('Cat_Codes'[GL_code]),'Amount_Table'[GL_code])
)

vcgaomsft_3-1725850101990.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
AnkitKukreja
Super User
Super User

Hi! @RichOB 

 

As suggested by @v-cgao-msftthis can be achieved with or without the relationship between the tables. In case your model has these 2 tables only then best practice would be to have a relationship between the tables and your measure should also work or you can add filter to the page while simply using sum measure.

 

 

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904
https://topmate.io/ankit_kukreja
v-cgao-msft
Community Support
Community Support

Hi @RichOB ,

 

If the filter from the ‘Cat_Codes’ table can be passed to the ‘Amount_Table’ table, then there seems to be no problem with your code, you just need to add double quotes to the text values in it:

vcgaomsft_0-1725849709478.png

IN {"Utilities", "Training", "Cleaning"}

Or you want that part of the result to be dynamic:

Combined_Amount = 
CALCULATE(
    SUM(Amount_Table[Balance])
)

vcgaomsft_1-1725849760677.png

Either there is no relationship between the two tables, or the filter cannot be passed.

vcgaomsft_2-1725849900347.png

Fixed:

Combined_Amount = 
CALCULATE(
    SUM(Amount_Table[Balance]),
    TREATAS(CALCULATETABLE(VALUES('Cat_Codes'[GL_code]),'Cat_Codes'[Category_name] IN {"Utilities", "Training", "Cleaning"}),'Amount_Table'[GL_code])
)

  Dynamic:

Combined_Amount = 
CALCULATE(
    SUM(Amount_Table[Balance]),
    TREATAS(VALUES('Cat_Codes'[GL_code]),'Amount_Table'[GL_code])
)

vcgaomsft_3-1725850101990.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

bhanu_gautam
Super User
Super User

@RichOB , Try this

 

Combined_Amount =
CALCULATE(
SUM(Amount_Table[Balance]),
FILTER(
Cat_Codes,
Cat_Codes[Category_name] IN {"Cleaning", "Training", "Utilities"}
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.