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
RogerSteinberg
Post Patron
Post Patron

Sum values group by a few categories with conditions

Hi,

I have a table that looks like this: 

User IDmembercategory Acategory bAmountTransaction DateEnter DateSourceOrder ID
123abcaabb $       1.002/8/2021 0:002/8/2021 0:00O987
123abcaabb $       1.002/8/2021 0:002/9/2021 0:00O987
999zzzaabb $       1.002/8/2021 0:002/8/2021 0:00Z321
999zzzaabb $       1.002/8/2021 0:002/8/2021 0:00Z321

 

I actually have way more columns than this but all i need is to create a measure  that calculates the total amount generated each day without duplicating the values with the following two conditions:

1. category A is AA and

2. category B is BB

 

My total amount should be 2$.

So essentially in SQL it should be 

select transaction_date,sum(amount) as total

from (

select transaction_date,order_id, amount

from table

where categoryA = 'aa' and categoryB = 'bb'

group by transaction_date, order_id,amount ) as base

group by transaction_date

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

Hi, @RogerSteinberg 

According to your SQL query and sample data, I can understand the output you want to get, we usually use “Calculated table” to achieve the “Select” function in SQL, you can create a Calculated table like this:

This is my test data based on your sample data:

v-robertq-msft_0-1613117682799.png

Table 2 =

SUMMARIZE(

    FILTER('Table',[category A]="aa"&&[category b]="bb"),

    'Table'[Transaction Date],

    'Table'[Order ID],

    "Total",SUM('Table'[Amount]))

 

And you can get what you want, like this:

v-robertq-msft_1-1613117682809.png

 

You can download my test pbix file here

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

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

View solution in original post

4 REPLIES 4
v-robertq-msft
Community Support
Community Support

Hi, @RogerSteinberg 

According to your SQL query and sample data, I can understand the output you want to get, we usually use “Calculated table” to achieve the “Select” function in SQL, you can create a Calculated table like this:

This is my test data based on your sample data:

v-robertq-msft_0-1613117682799.png

Table 2 =

SUMMARIZE(

    FILTER('Table',[category A]="aa"&&[category b]="bb"),

    'Table'[Transaction Date],

    'Table'[Order ID],

    "Total",SUM('Table'[Amount]))

 

And you can get what you want, like this:

v-robertq-msft_1-1613117682809.png

 

You can download my test pbix file here

 

If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

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

vanessafvg
Super User
Super User

well this calculation will give you that answer but it just depends on how you want to use it, in an aggregated visual, or in a row context?

 

total amount = CALCULATE(sum(data[Amount]), FILTER( data, data[category A] = "aa" && data[category b] ="bb"))




If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




that solution is not grouping by the dimensions. it will add duplicate values

Hi yes Roger that is why I asked how do you want to use this measure, that will define the solution, please give an example of what kind of visual you want to use it in, or how you plant to use this information.   Creating this measure as a calculated column will always give you total of 2 in any context.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




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.