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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
HaniMoussa
New Member

Dax formula

Hello,

           thanks for the time to read this problem and try to solve it.

I have two columns the first one

Product_idproduct_namecategorylist_price
1Dr Martenshoes $   34.34
2Roboshoeesshoes $   54.00
3Levi'spants $   22.00
4plain whiteShirts $   11.00
5lumberjackShirts $      6.00
6Button DownShirts $   21.00

and the second table

produt_iddiscount
10.1
20
30
40
50
10.3
20
20
30.5
40
50
61
10
20
30
40
50
30

 

and now I want to apply the discount from Table 2 to the prices in Table 1 and create a measure, to sum up the prices for all products.

Thanks

 

1 ACCEPTED SOLUTION

Hi, @HaniMoussa 

Thank you very much for your reply. Based on your description, you need to map the price in table1, here's how I did it:

Price =
CALCULATE (
    MAX ( 'Table'[list_price] ),
    FILTER ( 'Table', 'Table'[Product_id] = 'Table1'[produt_id] )
)
New price =
IF (
    'Table1'[discount] <> 0,
    CALCULATE ( MAX ( 'Table1'[discount] ) * MAX ( 'Table1'[Price] ) ),
    'Table1'[Price]
)

Here are the results:

vjianpengmsft_0-1713162828667.png

Sum price discount = SUM(Table1[New price]) 
Sum Price no discount = SUM(Table1[Price]) 

Use these two measures in the table visual:

vjianpengmsft_1-1713163017150.png

I've provided the PBIX file used this time below.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

7 REPLIES 7
v-jianpeng-msft
Community Support
Community Support

Hi, @HaniMoussa 

Thanks @Sergii24 . Based on your description, I used the following sample data:

vjianpengmsft_0-1712641582113.png

vjianpengmsft_1-1712641598089.png

I created a calculated column as shown in the image below:

Newprice =
VAR _currentid = 'Table'[Product_id]
VAR _discount =
    CALCULATE (
        SUM ( Table1[discount] ),
        FILTER ( 'Table1', 'Table1'[produt_id] = _currentid )
    )
RETURN
    SWITCH ( _discount, 0, 'Table'[list_price], 'Table'[list_price] * _discount )

vjianpengmsft_2-1712641888537.png

I use the following measure to find the total selling price of all products:

Total price = CALCULATE(SUM('Table'[Newprice]),ALL('Table'))

vjianpengmsft_3-1712641976040.png

I've provided the PBIX file used this time below.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

now in Table 1, I made sales operations with different discount ratios for each client buying a dedicated product.

I want to use the prices, apply these ratios, and then calculate the sum (for both before and after discount prices).

Thanks for your support

 

Hi, @HaniMoussa 

Thank you very much for your reply. Can you give us an indication of the output you are expecting based on the sample data you provided?e.g. when Product_id=1, there are multiple discounts in table 2, are they summed and then applied to table 1?

 

 

 

Best Regards

Jianpeng Li

order_idprodut_iddiscount
110.1
220
330
440
550
610.3
620
720
830.5
940
1050
1161
1210
1320
1430
1540
1650
230

there is table one for the deals and the applied discount

idproduct_namecategorylist_price
1Dr Martenshoes $   34.34
2Roboshoeesshoes $   54.00
3Levi'spants $   22.00
4plain whiteShirts $   11.00
5lumberjackShirts $      6.00
6Button DownShirts

 $   21.00

this is the second table for the prices of items

what I search for if this applicable is "  create a price column in table one mapping the price from table two to calculate the total income and another column with discounted price to compare both outputs"

Hi, @HaniMoussa 

Thank you very much for your reply. Based on your description, you need to map the price in table1, here's how I did it:

Price =
CALCULATE (
    MAX ( 'Table'[list_price] ),
    FILTER ( 'Table', 'Table'[Product_id] = 'Table1'[produt_id] )
)
New price =
IF (
    'Table1'[discount] <> 0,
    CALCULATE ( MAX ( 'Table1'[discount] ) * MAX ( 'Table1'[Price] ) ),
    'Table1'[Price]
)

Here are the results:

vjianpengmsft_0-1713162828667.png

Sum price discount = SUM(Table1[New price]) 
Sum Price no discount = SUM(Table1[Price]) 

Use these two measures in the table visual:

vjianpengmsft_1-1713163017150.png

I've provided the PBIX file used this time below.

 

 

 

 

How to Get Your Question Answered Quickly

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Jianpeng Li

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

 

Thanks for your support, done

Sergii24
Super User
Super User

Hi @HaniMoussa, I see that you have multiple discounts for the same product in the second table (example product ID 1). So what value do you want to apply: 0.1, 0.3 or 0 and based on what criteria?

The general suggestion I'd give you is to create a relatinship between these table (or use a bridge table that contains distinct values of Product ID). In that way, by using Product ID from this new table you can get the access to all prices and discounts of related product.

Good luck! 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.