cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
robin_ozc
Frequent Visitor

Return date when expected goal is reached

Hi all,

 

i'm trying to write a DAX formule to return a date when a certain number is reached. So i have 2 tables:

The first one is a table containing the minimum goals for HP and HC

HPHC
2000
3000
50050
750100

 

The second table contains all addresses and an integer whether or not HP or HC has been met.  

address_id isHP  isHC  date_hp date_hc
111 2021-02-01  2021-04-01
210 2021-12-14  2022-04-04
300 2022-02-01  2022-06-19

 

Let's assume the current isHP = 199 and isHC = 48. Reaching isHP = 200 would be on 2022-02-01 and Reaching isHC = 50 would be 2022-06-19, how should i write the DAX for this?

 

I hope my question is clear and someone can point me in the right direction.

 

Tnx in advance!

1 ACCEPTED SOLUTION

Hi @robin_ozc ,

 

I add a Date column to the data table.

Date = 
IF (
    [workon_digging_start_planned] = "",
    BLANK (),
    LEFT ( [workon_digging_start_planned], 10 )
)

vkkfmsft_0-1643269669377.png

 

Then create the following measures.

ishcTotal = 
CALCULATE (
    SUM ( data[ishc] ),
    FILTER (
        ALL ( data ),
        data[project_id] = MAX ( data[project_id] )
            && data[Date] <= MAX ( data[Date] )
    )
)
ishpTotal =
CALCULATE (
    SUM ( data[ishp] ),
    FILTER (
        ALL ( data ),
        data[project_id] = MAX ( data[project_id] )
            && data[Date] <= MAX ( data[Date] )
    )
)
Measure = 
IF ( 
    ISBLANK ( SUM ( Planning[HC Goal] ) ) && ISBLANK ( SUM ( Planning[HP Goal] ) ),
    BLANK ( ), 
    CALCULATE (
        MIN ( data[Date] ),
        FILTER ( 
            data,
            [ishcTotal] >= SUM ( Planning[HC Goal] )
                && [ishpTotal] >= SUM ( Planning[HP Goal] )
        )
    )
)

 

If you want to keep the filters for the projects[project] and contractors[contractor], then you need to add these columns in the visual.

image.png


If you don't keep any filters then you can use these columns in the visual.

vkkfmsft_1-1643272407287.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

6 REPLIES 6
robin_ozc
Frequent Visitor

Hi @lbendlin, i placed it on the dropbox account: PBIX file with data 

Hi @robin_ozc ,

 

How do you calculate the growth of isHP and isHC? Is it sorted by address column in ascending order and then calculate the number of rows?

 

vkkfmsft_2-1643089818495.png

vkkfmsft_1-1643089555536.png

 

Best Regards,
Winniz

 

Hi @v-kkf-msft , any chance to look at the problem?

Hi @robin_ozc ,

 

I add a Date column to the data table.

Date = 
IF (
    [workon_digging_start_planned] = "",
    BLANK (),
    LEFT ( [workon_digging_start_planned], 10 )
)

vkkfmsft_0-1643269669377.png

 

Then create the following measures.

ishcTotal = 
CALCULATE (
    SUM ( data[ishc] ),
    FILTER (
        ALL ( data ),
        data[project_id] = MAX ( data[project_id] )
            && data[Date] <= MAX ( data[Date] )
    )
)
ishpTotal =
CALCULATE (
    SUM ( data[ishp] ),
    FILTER (
        ALL ( data ),
        data[project_id] = MAX ( data[project_id] )
            && data[Date] <= MAX ( data[Date] )
    )
)
Measure = 
IF ( 
    ISBLANK ( SUM ( Planning[HC Goal] ) ) && ISBLANK ( SUM ( Planning[HP Goal] ) ),
    BLANK ( ), 
    CALCULATE (
        MIN ( data[Date] ),
        FILTER ( 
            data,
            [ishcTotal] >= SUM ( Planning[HC Goal] )
                && [ishpTotal] >= SUM ( Planning[HP Goal] )
        )
    )
)

 

If you want to keep the filters for the projects[project] and contractors[contractor], then you need to add these columns in the visual.

image.png


If you don't keep any filters then you can use these columns in the visual.

vkkfmsft_1-1643272407287.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.

Hi @v-kkf-msft , that was absolutely wonderful!!! Thank you so much 🙏

I have one challenge left, but i'll try to figure it out myself first before bothering you 😁

lbendlin
Super User
Super User

Let's assume the current isHP = 199 and isHC = 48."

Please reflect that in your sample data. Please provide sanitized sample data that fully covers your issue. Paste the data into a table in your post or use one of the file services. Please show the expected outcome.

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

Power BI Dev Camp Session 22 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!