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
michielb
New Member

Sum of all quantities before a date in slicer

Hi,

 

I am new to this forum and relatively new to PowerBI.

I have a request to report the flow of goods in quantities in a Power BI report.

So, shelf stock at a start date + purchases from that date - sales from that date = shelf stock at end date.

 

That's not a big issue apart from the calculation of the shelf stock at the beginning. We use the Report Server version of Power BI with imported data. That data holds a field that has the change date of the stock. The user must be able to change the start and end date in the report with a slicer. To calculate the shelf stock at the start date all transactions before that date have to be summed up and presented in a column in the report. To do this I have to capture the start date the user picks. This start date comes from a calendar table that is joined with the change date in the data set. 

 

To accomplish this, I have put a slicer that holds the date from the calendar table. I use the slicer setting "after" to have only one date in the slicer (but it can also be a "between" range). This one date should be the start date. Next, I added a table with all the relevant columns and with the Edit Interactions button I changed the table not being filtered with this start date when the user changes the start date in the slicer. The report should not be filtered with that start date but instead all transactions before that start date have to be summed in one figure per stock item.

 

To capture the start date I use this dax code:

CALCULATE(MIN(Calendar[Date].[Date]); ALLSELECTED('Calendar'))

 

That works fine, but when adding this date to a measure that filters all transactions before that date (so the shelf stock on start date) I am lost. No matter what I do, there is no sum of quantities of all the transactions before that date. It appears that the start date that is being captured and shown correctly in the report (with the card visual) is not used in the sum-formula. Even not when I use a variable in the DAX formula or use a calculated column. In the formula it appears that the start date falls back to the first date in the calendar table, which is 2010-01-01. I can give all measures I have tested for far, but what should be the correct approach for this?

 

Hope someone can give me a hint.

 

1 REPLY 1
Greg_Deckler
Super User
Super User

Not sure I follow. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

But if I understand what you are going for, perhaps, Measure = SUMX(FILTER(ALL('Table'),'Table'[Date] <= SELECTEDVALUE('Table'[Date])),[Column])


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

Top Solution Authors