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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
osama_ayoub
Helper III
Helper III

summarize sales table to grouby product , month , year and percentage of monthly sales over yearly

I want to summarize sales table to show product , month , year and percentage of monthly sales over yearly sales ?

 

osama_ayoub_0-1676416511177.png

 

1 ACCEPTED SOLUTION

@osama_ayoub So:

Table = 
  VAR __Table = 
    SUMMARIZE(
      'Sales',
      [Product ID], [Year], [Month],
      "__TotalPriceSales", SUM('Sales'[Total Price Sales])
    )
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "__YearSales", SUMX(FILTER(__Table,[Year] = EARLIER([Year]) && [Product ID] = EARLIER([Product ID])),[__TotalPriceSales])
    )
  VAR __Table2 = 
    ADDCOLUMNS(
      __Table1,
      "__YearlyPercent", DIVIDE([__TotalPriceSales], [__YearSales])
    )
RETURN
  __Table2


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
FreemanZ
Super User
Super User

hi @osama_ayoub 

tried to get a solution based on a simplified dataset like:

FreemanZ_0-1676471040475.png

 

1) add a column like:

 

YYYYMM = FORMAT([Date], "YYYYMM")

 

2) plot the product, YYYYMM columns with a measure like:

 

Yearly% = 
VAR _a = SUM(TableName[Sales])
VAR _b =
CALCULATE(
    SUM(TableName[Sales]),
    LEFT(TableName[YYYYMM],4) = LEFT(MAX(TableName[YYYYMM]),4)
)
RETURN
DIVIDE(_a, _b)

 

or

 

Yearly%2 = 
VAR _a = SUM(TableName[Sales])
VAR _b =
CALCULATE(
    SUM(TableName[Sales]),
    YEAR(TableName[Date]) = YEAR(MAX(TableName[Date])),
    ALLSELECTED(TableName[YYYYMM])
)
RETURN
DIVIDE(_a, _b)

 

 

it worked like this:

FreemanZ_2-1676471907875.png

 

 

 

Thanks for your help,

I want to create new table in the data model because I will need this table to connet it to Model 

I need this table to summarize sales table to show product and month and year and sales for each month and percentage of monthly sales of each product over the  yearly sales for only each product not all prosucts.

 

osama_ayoub_0-1676491140416.png

 

 

Greg_Deckler
Community Champion
Community Champion

@osama_ayoub First, add a Year column:

Year = YEAR([Date])

If you want a summarized table, then you can do this:

Table = 
  VAR __Table = 
    SUMMARIZE(
      'Sales',
      [Product ID], [Year], [Month],
      "__TotalPriceSales", SUM('Sales'[Total Price Sales])
    )
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "__YearSales", SUMX(FILTER(__Table,[Year] = EARLIER([Year])),[__TotalPriceSales])
    )
  VAR __Table2 = 
    ADDCOLUMNS(
      __Table1,
      "__YearlyPercent", DIVIDE([__TotalPriceSales], [__YearSales])
    )
RETURN
  __Table2
    


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I want to divide the monthly sales for each product over the yearly sales for only this product ,So the denominator is the yearly sales for one product .

Thanks for your help @Greg_Deckler 

@osama_ayoub So:

Table = 
  VAR __Table = 
    SUMMARIZE(
      'Sales',
      [Product ID], [Year], [Month],
      "__TotalPriceSales", SUM('Sales'[Total Price Sales])
    )
  VAR __Table1 = 
    ADDCOLUMNS(
      __Table,
      "__YearSales", SUMX(FILTER(__Table,[Year] = EARLIER([Year]) && [Product ID] = EARLIER([Product ID])),[__TotalPriceSales])
    )
  VAR __Table2 = 
    ADDCOLUMNS(
      __Table1,
      "__YearlyPercent", DIVIDE([__TotalPriceSales], [__YearSales])
    )
RETURN
  __Table2


Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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