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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
PeterStuhr
Helper V
Helper V

Add Count and Sum to table based on multiple ifs

Hi all,

 

We have a "Discount Table" looking somewhat like this:

 

SupplierIDLanguageIDProductTypeIDWorkAreaIDDiscountSettings
111150%
121250%
121150%
131250%

 

Then we have a "Sales table" looking somewhat like this:

 

JobIDPriceSupplierIDLanguageIDProductTypeIDWorkAreaID
1001001111
1011001212
1021001312
1031001312
1041001211
1051001111
1061001211
1071001211
1081001312
1091001212
1101001212

 

I would like to get a "Job count" and "Price" for each "Setting" based on first table.

 

So I would like an output somewhat like this:

 

SupplierIDLanguageIDProductTypeIDWorkAreaIDDiscountSettingsNumber of JobsPrice
111150%2200
121250%3300
121150%3300
131250%3

300

 

I am not sure how to combine the tables without a "unique key". 

 

So an example for me would be to know the "Price" and "Job count" for each SupplierID=1, where LanguageID=1, ProductTypeID=1, WorkAreaID=1 and DiscountSettings=50%.

 

And then I would just need all possible combinations.

 

Please help! 🙂

 

 

2 ACCEPTED SOLUTIONS
parry2k
Super User
Super User

@PeterStuhr concatenate columns to create a surrogate key to set the relationship between tables and then you can get data from the table pretty easily.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

V-lianl-msft
Community Support
Community Support

Hi @PeterStuhr ,

 

Try create measures like below:

 

Price =
CALCULATE (
    SUM ( 'Table (2)'[Price] ),
    FILTER (
        'Table (2)',
        'Table (2)'[SupplierID] = MAX ( 'Table'[SupplierID] )
            && 'Table (2)'[ProductTypeID] = MAX ( 'Table'[ProductTypeID] )
            && 'Table (2)'[WorkAreaID] = MAX ( 'Table'[WorkAreaID] )
            && 'Table (2)'[LanguageID] = MAX ( 'Table'[LanguageID] )
    )
)

Job count=
CALCULATE (
    COUNT( 'Table (2)'[JobId] ),
    FILTER (
        'Table (2)',
        'Table (2)'[SupplierID] = MAX ( 'Table'[SupplierID] )
            && 'Table (2)'[ProductTypeID] = MAX ( 'Table'[ProductTypeID] )
            && 'Table (2)'[WorkAreaID] = MAX ( 'Table'[WorkAreaID] )
            && 'Table (2)'[LanguageID] = MAX ( 'Table'[LanguageID] )
    )
)

 

test_Add Count and Sum to table based on multiple ifs.PNG

 

Best Regards,
Liang
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

3 REPLIES 3
V-lianl-msft
Community Support
Community Support

Hi @PeterStuhr ,

 

Try create measures like below:

 

Price =
CALCULATE (
    SUM ( 'Table (2)'[Price] ),
    FILTER (
        'Table (2)',
        'Table (2)'[SupplierID] = MAX ( 'Table'[SupplierID] )
            && 'Table (2)'[ProductTypeID] = MAX ( 'Table'[ProductTypeID] )
            && 'Table (2)'[WorkAreaID] = MAX ( 'Table'[WorkAreaID] )
            && 'Table (2)'[LanguageID] = MAX ( 'Table'[LanguageID] )
    )
)

Job count=
CALCULATE (
    COUNT( 'Table (2)'[JobId] ),
    FILTER (
        'Table (2)',
        'Table (2)'[SupplierID] = MAX ( 'Table'[SupplierID] )
            && 'Table (2)'[ProductTypeID] = MAX ( 'Table'[ProductTypeID] )
            && 'Table (2)'[WorkAreaID] = MAX ( 'Table'[WorkAreaID] )
            && 'Table (2)'[LanguageID] = MAX ( 'Table'[LanguageID] )
    )
)

 

test_Add Count and Sum to table based on multiple ifs.PNG

 

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

parry2k
Super User
Super User

@PeterStuhr concatenate columns to create a surrogate key to set the relationship between tables and then you can get data from the table pretty easily.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Hi @parry2k 

 

Can you show me how you would do it?

 

I am quite new to this!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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