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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
EZiamslow
Helper II
Helper II

If value is between two numbers from another table

Look up table:

ProductStartStepEndStep
Apple17
Apple1936
Apple4146
Apple5461
Orange111
Orange3542
Orange5562

 

Fact table:

ProductStepYNQty
Apple6Yes5
Apple8No5
Apple60Yes4
Orange12No6
Orange45No6
Orange55Yes4

 

Result:

Apple = 9 qty (5+4)

Orange = 4 qty (4)

 

I'm trying to create a YN calculated column in the fact table. Yes/No if Step from fact table is between StartStep and EndStep from look up table. Then, filter YN column to calculate the total qty of the products.

 

What would be the best way to approach this? 

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

HI @EZiamslow 

 

Trty this code to add a new column by using DAX:

YN Column = 
VAR _Step = 'Fact'[Step]
RETURN
    IF (
        CALCULATE (
            COUNTROWS ( 'Look up' ),
            FILTER (
                'Look up',
                'Look up'[Product] = EARLIER ( 'Fact'[Product] )
                    && 'Look up'[EndStep] >= _Step
                    && 'Look up'[StartStep] <= _Step
            )
        ) > 0,
        "Yes",
        "No"
    )

 

Output:

VahidDM_0-1657932823700.png



Sample file attached for your reference

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

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

View solution in original post

2 REPLIES 2
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1657949059003.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

VahidDM
Super User
Super User

HI @EZiamslow 

 

Trty this code to add a new column by using DAX:

YN Column = 
VAR _Step = 'Fact'[Step]
RETURN
    IF (
        CALCULATE (
            COUNTROWS ( 'Look up' ),
            FILTER (
                'Look up',
                'Look up'[Product] = EARLIER ( 'Fact'[Product] )
                    && 'Look up'[EndStep] >= _Step
                    && 'Look up'[StartStep] <= _Step
            )
        ) > 0,
        "Yes",
        "No"
    )

 

Output:

VahidDM_0-1657932823700.png



Sample file attached for your reference

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

Appreciate your Kudos!! 

Badges.jpg

LinkedIn | Twitter | Blog | YouTube 

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

Find out what's new and trending in the Fabric Community.