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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Measure Using A Data Log Table

Hello, I have a sales log table described below, and a general calendar table with dates used for analysis. I'm looking to create a measure on the calendar table that will count the SaleStatus for each SaleID. For example on 10/15/2020, it will grab ID=1,4, and 6 because they were the most recent before that date. So 2 Open and 1 Closed.

 

IDSaleIDSaleStatusDate
122Open10/1/2020
222Closed11/1/2020
313Open9/1/2020
413Closed10/1/2020
513Closed11/1/2020
64Open10/1/2020
74Open11/1/2020
3 REPLIES 3
AnkitKukreja
Super User
Super User

Hi

Please try this:

CommunitySolution.JPG
Count =
VAR _MaxDate = CALCULATE( MAX( Calender[Date] ) , ALLSELECTED( Calender) )

VAR _MinDate = CALCULATE( MIN( Calender[Date] ) , All(Calender[Date] ) )

VAR _Count = IF( SELECTEDVALUE( Calender[Date] ) <= _MaxDate ,
CALCULATE( COUNT( 'Sales Log'[ID] ) , FILTER( ALLSELECTED( Calender[Date]),
Calender[Date] <= _MaxDate && Calender[Date] >= _MinDate )), BLANK() )
Return
_Count


Thanks,
Ankit

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904
rfigtree
Resolver III
Resolver III

If is this what you mean.

Seems to Work but probably a better way.

Try doing this with the wife yelling at me to come get dinner and dog haslting me for a walk.

mStatus:=var _salesid = CALCULATE(if(HASONEVALUE(Table1[SaleID]),VALUES(Table1[SaleID]),2),ALL('Calendar'))
var _maxDate=MAX('Calendar'[Date])
var _x = CALCULATE(MAX(Table1[ID]),FILTER(ALL(Table1),[SaleID]=_salesid),FILTER(ALL('Calendar'),'Calendar'[Date]<=_maxDate))
return CALCULATE(IF(HASONEVALUE(Table1[ID]),VALUES(Table1[SaleStatus])),FILTER(ALL(Table1),Table1[ID]=_x))

 

rfigtree_0-1611906744093.png

 

Anonymous
Not applicable

This seems to work when using SalesID as a row constraint, but still looking to use this in a PowerBI that just aggregates the count of Open/Closed on each date without displaying each SaleID. I'm also curious, in your variable _salesid, why would the IF statement return 2 as the third argument? 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.