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
Anonymous
Not applicable

2M Rolling Count, while respecting two separate date columns/conditions

Hi,

 

I'm having some trouble with creating a dax measure for my specific problem. 

 

I have a fact table containing claims related to specific orders (Claims[CNo]). The fact table have two important date columns; one of which is representing the production date of a product (Claims[PDate]) and the other which is representing the date where the customer has issued a claim related to the product sold (Claims[CDate]. Currently the claim date is connected to a calender dimension; Calendar[Date]. 

 

If a product is produced in january (as indicated in Claims[PDate]), I need to count claims occuring in january and february (as indicated by Claims[CDate]. I.e. i'm interested in a 2m rolling count of claims, assuming a specific production month. I'm planning to represent this data in a table, showing the stats for each month over several years. 

 

Thank you so much.

 

https://i.postimg.cc/13nhcKBq/picture.png 

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

Hi @Anonymous ,

 

Why you not connect the PDate with the calendar table? Then you can use the following measure.

 

Measure =
CALCULATE (
    COUNTROWS ( Claims ),
    FILTER (
        Claims,
        Claims[CDate] >= MIN ( Calendar[Date] )
            && Claims[CDate] <= EOMONTH ( MAX ( calendar[Date] ), 1 )
    )
)

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

 

Best Regards,

Dedmon Dai

View solution in original post

3 REPLIES 3
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

Why you not connect the PDate with the calendar table? Then you can use the following measure.

 

Measure =
CALCULATE (
    COUNTROWS ( Claims ),
    FILTER (
        Claims,
        Claims[CDate] >= MIN ( Calendar[Date] )
            && Claims[CDate] <= EOMONTH ( MAX ( calendar[Date] ), 1 )
    )
)

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

 

Best Regards,

Dedmon Dai

parry2k
Super User
Super User

@Anonymous you should have a relationship with calendar table on PDATE as well which will be inactive relationship and then you can add following measure to get the count:

 

Production Count = 
CALCULATE ( COUNTROWS ( YourTable ), USERELATIONSHIP ( Calendar[Date], YourTable[PDate] ) )

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi, and thanks for your help! 😊

 

I have included the suggestion into my PBI, but I am not sure how to connect all the dots. 

 

I am able to count claims occuring this or last month by applying:

Measure = Count(Claims[CNo])
Beginning = FIRSTDATE( DATESINPERIOD('Calendar'[Date], [Period End], -2, MONTH))
End = LASTDATE('Calendar'[Date])
2M = CALCULATE( [Measure],
DATESBETWEEN ('Calendar'[Date], [Period Start], [Period End]))
 
This essentially gives me the count of every claim this and last month. However, it counts independent of PDate, meaning that the production date could be in another month than last month (or another year for that matter). Any thoughts on how to make this connection to the above, i.e. force the model to only count claims this and last month - given that they were produced last month. 
 
Thanks!

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.