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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
A7Russ
Regular Visitor

Power Query to DAX

Hi every one,

I'm struck and really struggling to build a logic in power BI,  I'm looking for a solution to reslove in DAX.

i have this in my power query editor...and i dont work very well...some records dont match 

this is the result im looking for.

Output-ok.jpg

and this is what i get (some of the criteria are misclassified)

 

Output-wrong.jpg

 

Power Query Code

criteria 90%
last year - CP5
Last 2 yeasr - CP 4
last 5 years - CP 2

if [#"Fecha "] > #date(2022,1,1) and [Cumple]>90 then "CP5"
else if [#"Fecha "] > #date(2020,12,30) and [Cumple]>90 then "CP4"
else if [#"Fecha "] > #date(2017,1,1) and [Cumple]>90 then "CP2"

Criteria 60%
last year - CP4
Last 2 yeasr - CP 3
last 5 years - CP 1

else if [#"Fecha "] > #date(2022,1,1) and [Cumple]>60 then "CP4"
else if [#"Fecha "] > #date(2020,1,1) and [Cumple]>60 then "CP3"
else if [#"Fecha "] > #date(2017,1,1) and [Cumple]>60 then "CP1"

else "Null"

 

any help or advice is appreciated 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @A7Russ ,

Please refer to my pbix file to see if it helps you.

Create a measure.

Measure =
IF (
    MAX ( 'Table'[Cumple] ) > 90
        && MAX ( 'Table'[Fecha] ) > DATE ( 2022, 1, 1 ),
    "CP5",
    IF (
        MAX ( 'Table'[Cumple] ) > 90
            && MAX ( 'Table'[Fecha] ) > DATE ( 2020, 12, 30 ),
        "CP4",
        IF (
            MAX ( 'Table'[Cumple] ) > 90
                && MAX ( 'Table'[Fecha] ) > DATE ( 2017, 1, 1 ),
            "CP2",
            IF (
                MAX ( 'Table'[Cumple] ) > 60
                    && MAX ( 'Table'[Cumple] ) < 90
                    && MAX ( 'Table'[Fecha] ) > DATE ( 2022, 1, 1 ),
                "CP4",
                IF (
                    MAX ( 'Table'[Cumple] ) > 60
                        && MAX ( 'Table'[Cumple] ) < 90
                        && MAX ( 'Table'[Fecha] ) > DATE ( 2020, 1, 1 ),
                    "CP3",
                    IF (
                        MAX ( 'Table'[Cumple] ) > 60
                            && MAX ( 'Table'[Cumple] ) < 90
                            && MAX ( 'Table'[Fecha] ) > DATE ( 2017, 1, 1 ),
                        "CP1",
                        "Null"
                    )
                )
            )
        )
    )
)

Or create a column.

Column =
IF (
    'Table'[Cumple] > 90
        && 'Table'[Fecha] > DATE ( 2022, 1, 1 ),
    "CP5",
    IF (
        'Table'[Cumple] > 90
            && 'Table'[Fecha] > DATE ( 2020, 12, 30 ),
        "CP4",
        IF (
            'Table'[Cumple] > 90
                && 'Table'[Fecha] > DATE ( 2017, 1, 1 ),
            "CP2",
            IF (
                'Table'[Cumple] > 60
                    && 'Table'[Cumple] < 90
                    && 'Table'[Fecha] > DATE ( 2022, 1, 1 ),
                "CP4",
                IF (
                    'Table'[Cumple] > 60
                        && 'Table'[Cumple] < 90
                        && 'Table'[Fecha] > DATE ( 2020, 1, 1 ),
                    "CP3",
                    IF (
                        'Table'[Cumple] > 60
                            && 'Table'[Cumple] < 90
                            && 'Table'[Fecha] > DATE ( 2017, 1, 1 ),
                        "CP1",
                        "Null"
                    )
                )
            )
        )
    )
)

vpollymsft_0-1649382103059.png

If I have misunderstood your meaning, please provide your desired output and your pbix without privacy information.

 

Best Regards

Community Support Team _ Polly

 

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

2 REPLIES 2
Anonymous
Not applicable

Hi @A7Russ ,

Does that make sense? If so, kindly mark my answer as the solution to close the case please. Thanks in advance.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi @A7Russ ,

Please refer to my pbix file to see if it helps you.

Create a measure.

Measure =
IF (
    MAX ( 'Table'[Cumple] ) > 90
        && MAX ( 'Table'[Fecha] ) > DATE ( 2022, 1, 1 ),
    "CP5",
    IF (
        MAX ( 'Table'[Cumple] ) > 90
            && MAX ( 'Table'[Fecha] ) > DATE ( 2020, 12, 30 ),
        "CP4",
        IF (
            MAX ( 'Table'[Cumple] ) > 90
                && MAX ( 'Table'[Fecha] ) > DATE ( 2017, 1, 1 ),
            "CP2",
            IF (
                MAX ( 'Table'[Cumple] ) > 60
                    && MAX ( 'Table'[Cumple] ) < 90
                    && MAX ( 'Table'[Fecha] ) > DATE ( 2022, 1, 1 ),
                "CP4",
                IF (
                    MAX ( 'Table'[Cumple] ) > 60
                        && MAX ( 'Table'[Cumple] ) < 90
                        && MAX ( 'Table'[Fecha] ) > DATE ( 2020, 1, 1 ),
                    "CP3",
                    IF (
                        MAX ( 'Table'[Cumple] ) > 60
                            && MAX ( 'Table'[Cumple] ) < 90
                            && MAX ( 'Table'[Fecha] ) > DATE ( 2017, 1, 1 ),
                        "CP1",
                        "Null"
                    )
                )
            )
        )
    )
)

Or create a column.

Column =
IF (
    'Table'[Cumple] > 90
        && 'Table'[Fecha] > DATE ( 2022, 1, 1 ),
    "CP5",
    IF (
        'Table'[Cumple] > 90
            && 'Table'[Fecha] > DATE ( 2020, 12, 30 ),
        "CP4",
        IF (
            'Table'[Cumple] > 90
                && 'Table'[Fecha] > DATE ( 2017, 1, 1 ),
            "CP2",
            IF (
                'Table'[Cumple] > 60
                    && 'Table'[Cumple] < 90
                    && 'Table'[Fecha] > DATE ( 2022, 1, 1 ),
                "CP4",
                IF (
                    'Table'[Cumple] > 60
                        && 'Table'[Cumple] < 90
                        && 'Table'[Fecha] > DATE ( 2020, 1, 1 ),
                    "CP3",
                    IF (
                        'Table'[Cumple] > 60
                            && 'Table'[Cumple] < 90
                            && 'Table'[Fecha] > DATE ( 2017, 1, 1 ),
                        "CP1",
                        "Null"
                    )
                )
            )
        )
    )
)

vpollymsft_0-1649382103059.png

If I have misunderstood your meaning, please provide your desired output and your pbix without privacy information.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.