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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.