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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Summarize table by a DimDate table

I have data like this (you can copy/paste into Enter Data, dates in dd/MM/yyyy):

GROUPINOUTQuantity
A01/01/201805/01/20181
A01/01/201804/01/20181
A02/01/201806/01/20181
A02/01/201803/01/20181
A03/01/201807/01/20181
B01/01/201805/01/20181
B01/01/201804/01/20181
B02/01/201806/01/20181
B02/01/201803/01/20181
B03/01/201807/01/20181
C01/01/201805/01/20181
C01/01/201804/01/20181
C02/01/201806/01/20181
C02/01/201803/01/20181
C03/01/201807/01/20181

 

Each row is a transaction. The table shows when the quantity of something had entered and left each group. 

I want the "stock" in each group, each day. So for each day, sum quantity for the rows where

IN <= day && OUT > day

For group A, on 03/01/2018 you have 4 units (1º, 2º, 3º and 5º row, 4º row does not match the condition).

The expected result would be something like:

Group2.JPG

Or like this:
Group3.JPG

 

My attempt has been to make an unrelated dimdate table:

Calendar = CALENDAR(MIN(Process[IN]); MAX(Process[OUT]))

Group4.JPG

And try to use SUMMARIZECOLUMNS:

Process_Calculated = 
SUMMARIZECOLUMNS(
    Calendar[Date]; 
    Process[GROUP]; 
    "Quantity"; CALCULATE(
        SUM(Process[Quantity]); 
        'Calendar'[Date] <= SELECTEDVALUE(Process[IN]]) && 'Calendar'[Date] > SELECTEDVALUE(Process[OUT])
    )
)

But dates can´t be compared like this (also I think SUMMARIZECOLUMNS doesn´t have row context).

 

I have to use DAX (can´t use PowerQuery) beacause I plan to use this table inside a VAR in a measure so it is dynamic to slicers.

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

@Anonymous ,

 

Each row is a transaction. The table shows when the quantity of something had entered and left each group. 

I want the "stock" in each group, each day. So for each day, sum quantity for the rows where

IN <= day && OUT > day

For group A, on 03/01/2018 you have 4 units (1º, 2º, 3º and 5º row, 4º row does not match the condition).

The expected result would be something like:


There's no "day" column in your sample data. Could you clarify more details about your logic?

 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

Anyone knows how to calculate the stock with this logic in DAX?

Anonymous
Not applicable

Hi @v-yuta-msft ,

 

yeah, sorry. "Day" refers to every day in a calendar, I guess the best way to do this is with a calendar table not-connected to the main table.

 

The main table gives the IN/OUT date and the quantity, but I need to calculate the stock for every day, so another calendar table is needed.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.