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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Bandana_Havana9
New Member

Filter and Sum

Hi, 

 

I need add together the items sold based on specified sales code.  This is what I currently have, but it is not working. Do I need to create a measure for grouping the sales code first (1000, 2000, etc). And then create a measure for the adding the SUM of the specified sales code. 

 

Hopefully this makes sense. Let me know if you have any questions. 

 

Thanks!

 

Total Sold Grouped =
CALCULATE(
    SUM(TABLE 1[PRICE]),
    FILTER(
        SAPOSTED,
        VALUE(RELATED(TABLE 2[SALES CODE])) IN {1000,2000,3000,4000,5000}
    )
4 REPLIES 4
v-dineshya
Community Support
Community Support

Hi @Bandana_Havana9 ,

Thank you for reaching out to the Microsoft Community Forum.

 

Hi @KNP  and @Ahmed-Elfeel , Thank you for your prompt responses.

 

Hi @Bandana_Havana9 ,  Could you please try the proposed solutions shared by @KNP  and @Ahmed-Elfeel  ? Let us know if you’re still facing the same issue we’ll be happy to assist you further.

 

Regards,

Dinesh

Hi @Bandana_Havana9 ,

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.

 

Regards,

Dinesh

Ahmed-Elfeel
Resolver III
Resolver III

Hi @Bandana_Havana9,

 

Your approach is on the right track, but there are a few potential issues with the DAX formula Like:

  • You are using TABLE 1[PRICE] but filtering SAPOSTED
  • VALUE function might not be necessary if SALES CODE is already a numeric column
  • Relationship requirement - This assumes a proper relationship between the tables

So I have 3 Solutions for you the 1st approach is (If you have a relationship between tables) :

Total Sold Grouped =
CALCULATE(
    SUM('TABLE 1'[PRICE]),
    'TABLE 2'[SALES CODE] IN {1000,2000,3000,4000,5000}
)

 

The 2nd approach Using FILTER (if no direct relationship):

Total Sold Grouped =
CALCULATE(
    SUM('TABLE 1'[PRICE]),
    FILTER(
        'TABLE 2',
        'TABLE 2'[SALES CODE] IN {1000,2000,3000,4000,5000}
    )
)

 

Finally the Last approach Using TREATAS (alternative approach):

Total Sold Grouped =
CALCULATE(
    SUM('TABLE 1'[PRICE]),
    TREATAS({1000,2000,3000,4000,5000}, 'TABLE 2'[SALES CODE])
)

 

So to answer your questions:

  1. Do you need to create a measure for grouping sales codes first?

    • No you can directly filter them in the CALCULATE function as shown above
  2. Do you need a measure for adding the SUM?
    • The measures I provided already handle both the filtering and summing

 

Note:Use Option 1 if you have a proper relationship between TABLE 1 and TABLE 2. Use Option 2 if you don't have a direct relationship.

if this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly.
KNP
Super User
Super User

It's difficult to be sure without seeing your model and relationships, but, I would think this syntax should work.

 

Total Black = 
    CALCULATE(
        SUM(FactInternetSales[SalesAmount])
        , FILTER(DimProduct, DimProduct[Color] IN {"Black"})
    )

 

KNP_0-1760643810301.png

 

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.