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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.