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
WencyREN
Frequent Visitor

Need help with creating a calculated measure with filter in the data table

Dear all, I need help with creating a calculated measure, please instruct on how to create such a measure to meet the requirement and sample data below, Thank you in advance!

 

Background: each product has 3 development stages, and each stage has an approved date (for product C in this case, it doesn't have stage 3 / stage 3 approved date record line as it's still under development). I want to create a measure that apply below logic:
(1) Select the product that has completed the 3 stages of development (in this case - select products A, B)
(2) Following the above, calculate the days' difference between each product's Stage 3 approved date and Stage 1 approved date, to see if it takes more than 2 months from stage 1 to stage 3
(3) Following above, sum up the development cost for those products taking more than 2 months from Stage 1 - Stage 3 and display the sum up cost in visuals

 

ProductStageApproved stage dateDevelopment cost in value
A101-Jul-21100
A201-Nov-21200
A310-Dec-21400
B102-Aug-21300
B204-Sep-21250
B310-Dec-21200
C101-Feb-22400
C201-Mar-22500
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Picture1.png

 

expected outcome measure: = 
CALCULATE (
    SUM ( Data[Development cost in value] ),
    TREATAS (
        SUMMARIZE (
            FILTER (
                ADDCOLUMNS (
                    GROUPBY (
                        FILTER (
                            ADDCOLUMNS (
                                Data,
                                "@condition", COUNTROWS ( FILTER ( Data, Data[Product] = EARLIER ( Data[Product] ) ) )
                            ),
                            [@condition] = 3
                        ),
                        Data[Product],
                        "@mindate", MINX ( CURRENTGROUP (), Data[Approved stage date] ),
                        "@maxdate", MAXX ( CURRENTGROUP (), Data[Approved stage date] )
                    ),
                    "@diff", INT ( [@maxdate] - [@mindate] )
                ),
                [@diff] >= 60
            ),
            Data[Product]
        ),
        Data[Product]
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Picture1.png

 

expected outcome measure: = 
CALCULATE (
    SUM ( Data[Development cost in value] ),
    TREATAS (
        SUMMARIZE (
            FILTER (
                ADDCOLUMNS (
                    GROUPBY (
                        FILTER (
                            ADDCOLUMNS (
                                Data,
                                "@condition", COUNTROWS ( FILTER ( Data, Data[Product] = EARLIER ( Data[Product] ) ) )
                            ),
                            [@condition] = 3
                        ),
                        Data[Product],
                        "@mindate", MINX ( CURRENTGROUP (), Data[Approved stage date] ),
                        "@maxdate", MAXX ( CURRENTGROUP (), Data[Approved stage date] )
                    ),
                    "@diff", INT ( [@maxdate] - [@mindate] )
                ),
                [@diff] >= 60
            ),
            Data[Product]
        ),
        Data[Product]
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
tamerj1
Super User
Super User

Hi @WencyREN 

you may try

Months Approved Products Development Cost =
VAR FirstDate =
    MIN ( Table[Approved stage date] )
VAR LastDate =
    MAX ( Table[Approved stage date] )
VAR Duration = LastDate - FirstDate
VAR NumberOfSatages =
    COUNTROWS ( Table )
RETURN
    IF (
        NumberOfSatages = 3
            && Duration > 60,
        SUM ( Table[Development cost in value] )
    )
johnt75
Super User
Super User

Assuming that products must have passed stage 2 to be able to pass stage 3, and assuming that each product has only 1 entry per stage, you could do something like

Total Cost =
VAR passedStage3 =
    ADDCOLUMNS (
        CALCULATETABLE ( VALUES ( 'Table'[Product] ), 'Table'[Stage] = 3 ),
        "stage 1 date",
            VAR currentProduct =
                CALCULATE ( SELECTEDVALUE ( 'Table'[Product] ) )
            RETURN
                LOOKUPVALUE (
                    'Table'[Approved stage date],
                    'Table'[Product], currentProduct,
                    'Table'[Stage], 1
                ),
        "stage 3 date",
            VAR currentProduct =
                CALCULATE ( SELECTEDVALUE ( 'Table'[Product] ) )
            RETURN
                LOOKUPVALUE (
                    'Table'[Approved stage date],
                    'Table'[Product], currentProduct,
                    'Table'[Stage], 3
                )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Development cost in value] ),
        FILTER ( passedStage3, [stage 3 date] - [stage 1 date] > 60 )
    )

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.