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

Counting rows with dates before [any date from a date-table]

Hi,

I'm trying to find the number of items that we've purchased before any given time.

I'm starting with a table with one row per item and purchase date (simplified, there are a LOT more columns in the actual table):

zxmon21_1-1664295660922.png

I need to pivot "how many items were purchased before a given date", and put that on a timeline (that will extend over the dates on the datetable). I need to be able to apply pivot filters and row/columns to it, e.g. separate by Type.

The datetable is related to my PurchDate 

zxmon21_2-1664295979133.png

My DateTbl contains a measure:

 

InkDat2:=CALCULATE(COUNT(Inventarier[Type]);FILTER(Inventarier;max(DateTbl[Date])<=Inventarier[PurchDate]))

 

 

As you probably notice this will not work, as the relation filters out any Inventories with PurchDate < Date.

Actual result:

zxmon21_3-1664296333099.png

Desired result:

zxmon21_5-1664296504492.png

 

Surely there are other people who needed to do something like this? I can't think of a good search term...

1 ACCEPTED SOLUTION
v-yadongf-msft
Community Support
Community Support

Hi @zxmon21 ,

 

Please try following DAX:

Measure = IF(
    ISINSCOPE('Table'[Type]),
    CALCULATE(COUNT('Table'[Type]),FILTER(ALL('Table'),'Table'[Type] = SELECTEDVALUE('Table'[Type]) && 'Table'[PurchDate] <= SELECTEDVALUE('Date'[PurchDate]))),
    CALCULATE(COUNT('Table'[Type]),FILTER(ALL('Table'),'Table'[PurchDate] <= SELECTEDVALUE('Date'[PurchDate])))
)

vyadongfmsft_0-1664350356161.png

Best regards,

Yadong Fang

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

View solution in original post

2 REPLIES 2
v-yadongf-msft
Community Support
Community Support

Hi @zxmon21 ,

 

Please try following DAX:

Measure = IF(
    ISINSCOPE('Table'[Type]),
    CALCULATE(COUNT('Table'[Type]),FILTER(ALL('Table'),'Table'[Type] = SELECTEDVALUE('Table'[Type]) && 'Table'[PurchDate] <= SELECTEDVALUE('Date'[PurchDate]))),
    CALCULATE(COUNT('Table'[Type]),FILTER(ALL('Table'),'Table'[PurchDate] <= SELECTEDVALUE('Date'[PurchDate])))
)

vyadongfmsft_0-1664350356161.png

Best regards,

Yadong Fang

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

davehus
Memorable Member
Memorable Member

Hi @zxmon21 ,

 

Would a date filter in the filter pane not achieve the same result without the need for a measure?

 

Did I help you today? Please accept my solution and hit the Kudos button.

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.