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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
sandeep_sharma
Helper II
Helper II

count basis date

I have below data....there is another calendar table that has inactive relationship with Expiration date column...I want to count the items as per expiration date....so when I put calendar date in a table.....it should give the count of Items which have expiration date between the first and last day of that month......so for example in the table....it should give me the count of items with expiration date of Jun 2024 in front of Jun 2024 line item...can you suggest a measure

 

 

sandeep_sharma_0-1735905110099.png

 

1 ACCEPTED SOLUTION

For that you couldn't rely just on relationships, as only one can be active at a time. You would need something like

Billed and Expired =
VAR VisibleDates =
    VALUES ( 'Date'[Date] )
VAR Result =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        TREATAS ( VisibleDates, 'Table'[Expiry Date] ),
        TREATAS ( VisibleDates, 'Table'[Billing Date] )
    )
RETURN
    Result

View solution in original post

9 REPLIES 9
johnt75
Super User
Super User

Try

Num expirations =
CALCULATE (
    COUNTROWS ( 'Table' ),
    USERELATIONSHIP ( 'Date'[Date], 'Table'[Expiration Date] )
)

Looks good...but what if I need the count of items that were billed and expired in the same month as the calender date table....

 

 

 

 

 

For that you couldn't rely just on relationships, as only one can be active at a time. You would need something like

Billed and Expired =
VAR VisibleDates =
    VALUES ( 'Date'[Date] )
VAR Result =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        TREATAS ( VisibleDates, 'Table'[Expiry Date] ),
        TREATAS ( VisibleDates, 'Table'[Billing Date] )
    )
RETURN
    Result

Thanks @johnt75 

 

It worked but I had to use userrelationship to link it with expiration date....the data is showing correct in that case only...otherwise not sure how it is showing very very less numbers...anyways...this is a great help..thanks....got to learn a new thing today 🙂

though I have another condition I got stuck on....what if I need the count of items which got billed as the visiable date but got expired 2 months ago of visible dates

Hi,

Share data in a format that can be pasted in an MS Excel file.  Based on that data shared, show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

You can manipulate the filters for billing date and expired date independently, e.g.

Billed and Expired =
VAR VisibleDates =
    VALUES ( 'Date'[Date] )
VAR EarlierDates =
    DATEADD ( 'Date'[Date], -2, MONTH )
VAR Result =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        TREATAS ( EarlierDates, 'Table'[Expiry Date] ),
        TREATAS ( VisibleDates, 'Table'[Billing Date] )
    )
RETURN
    Result

Basically, you build a table of dates for use as the billing date and a separate table with potentially different dates for use as the expired date.

If you are going to have a lot of these types of manipulations it might be worth creating a calculation group with different calculation items for each combination you want to be able to show.

If I use this measure...it says a table of multiple values was supplied where a single value was expected and giving error....I have tried it with Max and selectedvalue as well...but of no use...

Can you post the exact code you are using ?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors