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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
remingtonh
New Member

Using a date table to dynamically calculate a measure

Hi all!
 
 

I'm attempting to use a date table,called date, formatted as so

Date         Month   Day   Year
01/01/2019   01      01    2019
01/02/2019   01      02    2019
....

with another table,called A, formatted as so

ID    DateStarted   Type
01    12/30/2018    apple
02    12/30/2017    apple
03    12/31/2018    carrot
...

I'd like to create a measure or something, so I can show in a graph dynamically the # of apples/carrots where the start date is within 12 months of some random date in the Date table (I'd like to show the Date tables ['Date'] field as my axis on a graph, with the calculated "within 12 months" as my value for instance, and then be able to use the "type" field as my legend value. So for the above example, I would see Jan-Dec of 2019 on the graph, and then see a value of 1 and 1 in Jan of 2019 for apples and carrots (as the other apple was shipped 24 months prior to that.) Then, in Feb of 2019 on the graph, both values would be 0.

I've attempted messing around with Countax, but I can't seem to get it to work, as there are multiple values in the Date table, and powerbi would like me to aggregate them.

Shipments in past 12 months = COUNTAX(MDBEQUIP,(DATEDIFF(Dates[Date],MDBEQUIP[Tag added date],MONTH)<12))

Is this the best approach? Another idea I had was trying to dynamically create a new table with all calculated columns with something like

Month    Type    Calculated column for above

But wasn't sure if there was another way.

1 REPLY 1
amitchandak
Super User
Super User

Check out this example where I have put a filter on the Last Qtr as well as on this QTR. Also, you might have put crossfilter.

 

 

Sales Before QTR = 
CALCULATE(SUMx(FILTER(sales,and(Sales[Order_Date]>= STARTOFQUARTER(DATEADD(STARTOFQUARTER(OrderTime[Order Date]),-1,DAY)) && Sales[Order_Date]<= DATEADD(STARTOFQUARTER(OrderTime[Order Date]),-1,DAY),
Sales[Requested_Date]>= STARTOFQUARTER(OrderTime[Order Date]) && Sales[Requested_Date]<= STARTOFQUARTER(OrderTime[Order Date])
)),Sales[Sales]),CROSSFILTER(Sales[Order_Date],OrderTime[Order Date],None))

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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