Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Match value in table A with B

Hi all, 

 

I am trying to write a measure to match the usage in table A with the pricing in table B. 

 

Table A: 

customer_nameTypeusageTier ranking pricing
AStandard20??
BStandard55??
CExecutive55??
DExecutive126??

 

Table B: 

TypeTier rankingMinMaxpricing
Standard105$0.00
Standard2615$50.00
Standard31635$48.00
Standard43670$45.88
Standard571125$43.63
Standard6126205$41.25
Executive105$100.00
Executive2615$95.00
Executive31635$90.00
Executive43670$85.00
Executive571125$80.00
Executive6126205$75.00

 

The DAX measure I need to calculate is the "Tier Ranking" and "Pricing" in table A; it would match the usage accordingly to the Min and Max in table B to decide which tier a customer is in, and how much they should be charged. 

 

So the result should be like this: 

customer_nameTypeusageTier ranking pricing
AStandard203$48.00
BStandard554$45.88
CExecutive554$85.00
DExecutive1266$75.00

 

I have been trying to use a lot of IF functions but it's not working. I greatly appreciate any advice and help! 

 

Thank you all, 

 

  • Hello Anonymous 

    If the Min values from table B are static then you can add a calculated column to get the Min target for Table A based on the usage.

    MinValue = 
    VAR RowUsage = TableA[usage]
    RETURN
    SWITCH (
        TRUE (),
        RowUsage < 6, 0,
        RowUsage < 16, 6,
        RowUsage < 36, 16,
        RowUsage < 71, 36,
        RowUsage < 126, 71,
        126)

    Then it is just a couple of LOOKUPVALUE columns to get Tier and Pricing

    Tier Ranking = 
    LOOKUPVALUE ( TableB[Tier ranking], TableB[Type], TableA[Type], TableB[Min], TableA[MinValue] )
    Pricing = 
    LOOKUPVALUE ( TableB[pricing], TableB[Type], TableA[Type], TableB[Min], TableA[MinValue] )

  • Hello Anonymous ,

    We can't easily create a calculated column on table A becasue the usage is a distinct count of table A.  This measure will pull the pricing based on the usage and tier though.

    Pricing = 
    VAR Tier = SELECTEDVALUE ( TableA[Tier Type] )
    RETURN
    CALCULATE(
        MAX(TableB[pricing]),
                FILTER(
                    TableB,
                    TableB[Type] = tier &&
                    [usage] >= TableB[Min]
                    && [usage] <= TableB[Max] )
        )

11 Replies

  • Hello Anonymous 

    If the Min values from table B are static then you can add a calculated column to get the Min target for Table A based on the usage.

    MinValue = 
    VAR RowUsage = TableA[usage]
    RETURN
    SWITCH (
        TRUE (),
        RowUsage < 6, 0,
        RowUsage < 16, 6,
        RowUsage < 36, 16,
        RowUsage < 71, 36,
        RowUsage < 126, 71,
        126)

    Then it is just a couple of LOOKUPVALUE columns to get Tier and Pricing

    Tier Ranking = 
    LOOKUPVALUE ( TableB[Tier ranking], TableB[Type], TableA[Type], TableB[Min], TableA[MinValue] )
    Pricing = 
    LOOKUPVALUE ( TableB[pricing], TableB[Type], TableA[Type], TableB[Min], TableA[MinValue] )

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi jdbuchanan71 , thank you very much for your solution. It works perfectly for this sample model. However, when I apply to my actual model, where the "usage in table A is a measure (distinct count of a text), the calculated column MinValue does not work. It returns 0 for all. I am not sure how to work around this issue. Thank you very much for your help. 

      • jdbuchanan71's avatar
        jdbuchanan71
        Icon for Super User rankSuper User

        Anonymous 

        Try adding the usage as a calculated column in Table A simply by adding a column and putting in =[usage measure].  Does that get you what you need?  If not, please share your .pbix file so we can see how the data is actually organized.