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
Pbiuserr
Post Prodigy
Post Prodigy

Sum of MinDate for Each ID with status each month

Hello,

I am trying to get sum of broken items per month for each ID within status for the earliest date available in the dataset (as they continously are in dataset for next months with the same status, but I want to count it only once in the month it has broke)

Status has to be = "B". I also need to use relationship because I have already established active relation between Active items and calendar 

 

So I was thinking of 

Calculate ( SUM ( ItemID ),
Table[ItemStatus] = "B",
MIN( Table[InActiveItemsDat] ),
USERELATIONSHIP ( Table[InActiveItemsDat], Calendar[Date] )
 )
however it doesnt work

 

1 ACCEPTED SOLUTION

Hi @Pbiuserr ,

 

Please try these measures to see if they return correct result.

 

FirstDate = 
CALCULATE (
    MIN ( 'Calendar'[Date] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[ItemStatus] = "B"
            && 'Table'[ItemID] = MAX ( 'Table'[ItemID] )
    ),
    ALL (),
    USERELATIONSHIP ( 'Calendar'[Date], 'Table'[InActiveItemsDat] )
)
IDCount = 
SUMX (
    'Table',
    CALCULATE (
        COUNTROWS ( 'Calendar' ),
        FILTER ( 'Calendar', 'Calendar'[Date] = [FirstDate] ),
        USERELATIONSHIP ( 'Calendar'[Date], 'Table'[InActiveItemsDat] )
    )
)

vkkfmsft_1-1657863334719.png

vkkfmsft_0-1657863267523.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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

3 REPLIES 3
amitchandak
Super User
Super User

@Pbiuserr , You need to try a measure like

 

Calculate ( SUM ( ItemID ),
Filter( Table, Table[ItemStatus] = "B" && Table[InActiveItemsDat] = minx(filter(allselected(Table), Table[ID] = Max(Table[ID])), Table[InActiveItemsDat]))
USERELATIONSHIP ( Table[InActiveItemsDat], Calendar[Date] )
)

 

 

refer

https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

Hi,

unfortunately it gives me blank value, so it doesnt count 

Hi @Pbiuserr ,

 

Please try these measures to see if they return correct result.

 

FirstDate = 
CALCULATE (
    MIN ( 'Calendar'[Date] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[ItemStatus] = "B"
            && 'Table'[ItemID] = MAX ( 'Table'[ItemID] )
    ),
    ALL (),
    USERELATIONSHIP ( 'Calendar'[Date], 'Table'[InActiveItemsDat] )
)
IDCount = 
SUMX (
    'Table',
    CALCULATE (
        COUNTROWS ( 'Calendar' ),
        FILTER ( 'Calendar', 'Calendar'[Date] = [FirstDate] ),
        USERELATIONSHIP ( 'Calendar'[Date], 'Table'[InActiveItemsDat] )
    )
)

vkkfmsft_1-1657863334719.png

vkkfmsft_0-1657863267523.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.