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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Arentir
Resolver III
Resolver III

Create Measure based on different row (date)

Hi guys,

 

I am trying to create a report on Power BI but can't pin the right way although the goal seems very simple.

 

Here is my sample data below. I want to create a measure that will do the sum of quantity for the next day (and eventually date +2 and date +3). So I am looking somewhat to override the filter on the date and apply next day instead.

 

I simplified the sample to two dimensions but I would eventually have more (product category, supplier..)

Sample:

DateNameQuantity
01/01/2017A5
01/01/2017A5
01/01/2017B5
02/01/2017A1
02/01/2017A2
02/01/2017B2
02/01/2017B3

 

 What I am trying to achieve:

DateNameSum(Qty)Sum(Next_Day_Qty)
01/01/2017A103
01/01/2017B55
02/01/2017A3 
02/01/2017B5 

 

Thanks 

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

NextDay Totals =
CALCULATE ( SUM ( 'Table'[Quantity] ), DATEADD ( 'Calendar'[Date], +1, DAY ) )

View solution in original post

5 REPLIES 5
ImkeF
Community Champion
Community Champion

You can use the DATEADD-function to shift your Date-filters forward or backward:

https://msdn.microsoft.com/en-us/library/ee634905.aspx

 

This requires a separate calendar-table (DateTime), which is one of the best practices for PBI like described here: http://exceleratorbi.com.au/best-practices-power-pivot-power-query-power-bi/ 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Sean
Community Champion
Community Champion

NextDay Totals =
CALCULATE ( SUM ( 'Table'[Quantity] ), DATEADD ( 'Calendar'[Date], +1, DAY ) )

Sean I believe your solution is close to what I am looking for.

 

I have written the formulas as :

 

Spoiler
NextDay Total = CALCULATE(SUM('Product'[Quantity]),DATEADD('Product'[Date],1,DAY))

Note that I am using the same table for Quantity and Date. It works like a charm with the current sample, I have tried to add one product C with non following date for test:

 

 

 

Capture1.PNG

 

It looks fine at first

Capture2.PNG

But when I filter C I get this message

Capture3.PNG

 

Fair enough, I have tried to add a calendar table relating to Product table and changed the measure to:

 

Spoiler
NextDay Total = CALCULATE(SUM('Product'[Quantity]),DATEADD('Calendar'[Date],1,DAY))

The measure looks like a simple Sum(Quantity)

Capture4.PNG

 

 

 

 

 

 

 

 

Sean
Community Champion
Community Champion

Replace Product[Date] in the Table Visual with Calendar[Date] Smiley Happy

Thanks Sean it was simple as that!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.