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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Marcox28
Helper II
Helper II

SUM SALES WITH PROMO

I have a problem in calculating sales made with receipts with at least one product being promoted.

 

my sales table is

 

TVE_IDTVE_IdArticoloTVE_PriceTVE_CodicePromozioneTVE_IDScontrino
18389683,954441
28549782,03    1
385087510    1
485357627,99    2
585357627,99    2
681020327,99    2
785357627,99    3
881020327,994444
984975710    4
108383662,99    4
118383662,99    4
128383662,99    5
138551442,49    5
148226733,59    5
1583517519    5
1683663423,92    5
1783426138,5    6
188343086,474447
198549632,03    8
208549662,03    8
218549672,03    8
228549602,73    8
2384783727,9    9
2483433014,974449
2581582319,95    9

 

where is it

TVE_ID indicates sales line ID

TVE_price indicates the selling price

TVE_codicepromo indicates the code of the promotion

TVE_IDScontrino indicates the receipt number.

 

How can I calculate the sum of all receipts that contain at least one product in promotion 444?

 

I expect this result to come: promotional sales = 129.24

because it sum the following sales line

 

TVE_IDTVE_IdArticoloTVE_PriceTVE_CodicePromozioneTVE_IDScontrino
18389683,954441
28549782,03    1
385087510    1
881020327,994444
984975710    4
108383662,99    4
118383662,99    4
188343086,474447
2384783727,9    9
2483433014,974449
2581582319,95    9

 

44 REPLIES 44
Anonymous
Not applicable

I'm confused. I see only four lines coded to the promo and they do not add over $100. If there is no code in the lines I do not know how to pull those out.

yes, four lines that are part of 4 receipts containing, in some cases also products not sold in promotion. I would also like to add those lines as you can see from the second table.

the sales lines are part of the same receipt if they have the same TVE_IDScontrino

Hello, @Anonymous
If i correct understud your case, i hope formula below help you.

 

Promotional sales =
CALCULATE (
    SUM ( SalesTable[TVE_price] ),
    SUMMARIZE (
        FILTER ( SalesTable, NOT ISBLANK ( SalesTable[TVE_codicepromo] ) ),
        SalesTable[TVE_IDScontrino]
    )
)

Anonymous
Not applicable

That only adds up where there is a promo code. The Measure needs to select TVE_IDScontrino where Promo is not null and add the Sales for the rows with those TVE_IDScontrino.

 

I'm thinking it's a column that brings in the TVE_IDScontrino where TVE_CodicePromozione NOT ISBLANK. Then use that column for a Measure to Sum.

 

TVE_IDScontrinoTVE_Price
115.98
443.97
76.47
962.82
 129.24

this formula is not correct for me because it only returns the sum of the rows that have TVE_codicepromo 444.

so with result 53.38.

while I need to calculate the sum of all receipts that contain at least one product in promotion then with a total of 129.24

TVE_IDTVE_IdArticoloTVE_PriceTVE_CodicePromozioneTVE_IDScontrino
18389683,954441
28549782,03    1
385087510    1
881020327,994444
984975710    4
108383662,99    4
118383662,99    4
188343086,474447
2384783727,9    9
2483433014,974449
2581582319,95    9

 

 

the color of the characters helps you to understand that the lines of the same character are part of the same receipt. I can distinguish them through the TVE_IDScontrino

@Anonymousin my opinion @popov measure should work. I guess you tried and not worked, can you share how you did it?



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.

Anonymous
Not applicable

I simply copied the example table in the original post into BI. I then created a Measure using the formula given. It only brings in the Sum of the four rows with the Promo Code. It ignores the receipts for the Promo where the promo is Null. 

Seeme like somethign else is going on, I tested it on my end with sample data and it worked fine.



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.

Anonymous
Not applicable

Did you get 129.24 ?

 

Here's the code:

 

Promotional sales =
CALCULATE (
SUM ( SalesTable[PRICE] ),
SUMMARIZE (
FILTER ( SalesTable, NOT ISBLANK ( SalesTable[TVE_CodicePromozione] ) ),
SalesTable[TVE_IDScontrino]
)
)

 

Here is the result: It only pulls in the four rows with the PromoID

TVE_IDPromotional salesPRICE
13.953.95
2 2.03
3 0.1
4 27.99
5 27.99
6 27.99
7 27.99
827.9927.99
9 0.1
10 2.99
11 2.99
12 2.99
13 2.49
14 3.59
15 0.19
16 23.92
17 3.85
186.476.47
19 2.03
20 2.03
21 2.03
22 2.73
23 2.79
2414.9714.97
25 19.95

 

price.PNG

 

Sorry when I imported the data, you have comma which turn out to be number for not decimal but anyhow you have the idea that it works, not sure why you have price and id in the table. 



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.

Anonymous
Not applicable

Price is a Measure dividing the Imported price with a Comma by 100 to get the values in the example.

 

You are not getting the right value. The value in your example should be 12,924. You are not picking up all the sales for the receipt IDs.

 

TVE_IDTVE_IdArticoloTVE_PriceTVE_CodicePromozioneTVE_IDScontrino
18389683.954441
881020327.994444
188343086.474447
2483433014.974449
28549782.03These are NULL but still need to be added in1
3850875101
9849757104
108383662.994
118383662.994
2384783727.99
2581582319.959
     
  129.24  

attached, check and let me know what we are missing.



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.

Anonymous
Not applicable

Sorry parry. You are not listening. My latest example was quite explicite. This shouldn't be that hard but it is. Rather fun. 

although I found your reply bit rude "you are not listening", dude we all are helping each other here and I'm doing my best to get what you are lookig for.



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.

Anonymous
Not applicable

Sorry, you are right. 

 

You insist that the 84 is the right number. It is not.  All Receipt IDs of 1,4,7,9 need to be added in despite that only one row for each ID has a promo code in it. 

 

That requires a nested "query" to pull out the Receipt ID for promos and then sum all rows with those receipt IDs. 

Anyhow, I guess you have the solution, you have to look data in my pbix file and then just use and apply on your data. Good luck. 



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.

I think, I know what the problem. You are filtering data by column TVE_codicepromo. This formula is correct:

Promotional sales =
CALCULATE (
    SUM ( SalesTable[TVE_price] ),
    SUMMARIZE (
        FILTER ( SalesTable, NOT ISBLANK ( SalesTable[TVE_codicepromo] ) ),
        SalesTable[TVE_IDScontrino]
    ),
    ALL ( SalesTable[TVE_codicepromo] )
)

@Marcox28, @Anonymous, @parry2k@popov - In response to a private message, I believe the measure that you are looking for is this:

 

Sum in Promo = 
VAR __values = SELECTCOLUMNS(FILTER(table9,[TVE_CodicePromozione]=444),"__SearchValues",[TVE_IDScontrino])
VAR __tmpTable = ADDCOLUMNS('Table9',"__In",IF([TVE_IDScontrino] IN __values,TRUE,FALSE))
RETURN SUMX(FILTER(__tmpTable,[__In]),[TVE_Price])

Returns $129.24 with the data provided in the original post. 

 

Walking through the code:

  • First line gets the values of IDScontrino that have at least one item matching 444 as the promo code.
  • Creates a temporary table that returns the original table with an added column of either TRUE or FALSE. This additional column is calculated such that it checks if the IDScontrino in each row is "IN" the previously computed values table returned in the first line. If so, then TRUE, if not then FALSE
  • Does a simple SUMX on the table filtered such that "__In" is TRUE.

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

You are the best Greg. I knew it most likely relyed on a column or a view (temp table). 

 

Question: How do we pull in the TVE_IDScontrino for any Promo (NOT ISBLANK) so the promo number doesn't have to be manually in the script? I failed.

 

Thank you. This is much needed to this old SQL guy who lived by nested queries to solve such things. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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