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
Ramps
Helper I
Helper I

Convert weekly totals by product into a YTD weekly running total by product

If a data source contains:-

  • Product
  • Week number
  • Weekly qty

How can a table report be produce with YTD qty by product by week number.

Note the date source may not have entries for every week, for example Phones were sold in week 1,2 & 4 but not 3,5 & 6. However, the report requires YTD qtys for each product each week.

 

 

I assume a week table, a relationship and a DAX measure or column could be used or convert the week into a date and use the date table. Examples of both methods would be helpful.

 

I have programmed in other languages but new to DAX. I looked at other posts on the forum and found them confusing becauseI I have not got to grasp with DAX sytntax yet, please can anyone provide a clear examples for a DAX beginner. Thank you.

 

SOURCE DATA   
ProductWeekWeekly Qty 
Phone125 
Phone217 
Phone48 
Radio131 
Radio434 
Radio619 
TV214 
TV428

 

 

DESIRED REPORT
ProductWeekWeekly QtyYTD Qty
Phone12525
Phone21742
Phone3 42
Phone4850
Phone5 50
Phone6 50
Radio13131
Radio2 31
Radio3 31
Radio43465
Radio5 65
Radio61984
TV1 0
TV21414
TV3 14
TV42842
TV5 42
TV6 42
3 REPLIES 3
v-jiascu-msft
Employee
Employee

Hi @Ramps,

 

Please check out the demo here.

1. A week table full of weeks.

Weeks = GENERATESERIES(1, 52, 1)

2. A product table full of products.

Products = VALUES('SOURCE DATA'[Product])

3. Establish relationships.

4. Create a measure.

YTW =
VAR ytw =
    CALCULATE (
        SUM ( 'SOURCE DATA'[Weekly Qty] ),
        FILTER ( ALL ( Weeks ), 'Weeks'[week] <= MIN ( 'Weeks'[week] ) )
    )
RETURN
    IF ( ISBLANK ( ytw ), 0, ytw )

5. Create a visual and enable "Show data without values".

Convert_weekly_totals_by_pr

 

Best Regards,

Dale

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

Many thanks Dale of going to the effort to creating a PBIX example 

It is really helpful and I will use it. Thank you.

 

This formula is great for viewing in tables but I am still having problems with the line graphs.

See my post about  "Line graph comparing a year's forecast with YTD sales."

 

https://community.powerbi.com/t5/Desktop/Line-graph-comparing-a-year-s-forecast-with-YTD-sales/m-p/3...

 

Many thanks

 

Greg_Deckler
Super User
Super User

RunningTotal = 
VAR MyWeek = MAX(WeeklyTotals[Week])
VAR MySum = CALCULATE(SUM([Weekly Qty]),FILTER(ALLEXCEPT(WeeklyTotals,WeeklyTotals[Product]),[Week]<=MyWeek))
RETURN MySum

@ 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...

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.