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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Slowik131
Helper I
Helper I

Show values only if they exist in another table

Hi,

 

I have tables that when simplified look like this:

 

Table A

Slowik131_0-1715514668193.png


Table B

Slowik131_1-1715514702916.png

 

Essentially what I want to end up is, is a measure that would sum up the tarif_kpi column from Table B only if the values for ID's exist in the Table A.

 

So in this simplified case, to sum up tarif_kpi where package_id in [1,2,3] and comm_id in [1,2].

 

I tried to achieve it with TREATAS() like that:

 

tarif treatas = VAR sales = SUMMARIZE('Sales', 'Sales'[Date], 'Sales'[Package_ID], 'Sales'[Comm_ID])

VAR filtered = TREATAS(sales, 'Calendar'[Dates], Packages[ID Package], 'Commercial Organisation'[ID Org Com])

RETURN
CALCULATE(SUM(ARPU[tarif_kpi]), KEEPFILTERS(filtered))

 

 

Unfortunately it doesn't work correctly.

 

Do you have any idea how to make it work?

Thanks!

 

1 ACCEPTED SOLUTION

So something like this?

 

 

tarif treatas 2 = VAR sales = SUMMARIZE('Sales', 'Sales'[Date], 'Sales'[Package_ID], 'Sales'[Comm_ID])

VAR filtered = TREATAS(sales, 'ARPU'[Date], ARPU[ID Package], 'ARPU'[ID Org Com])

RETURN
CALCULATE(SUM(ARPU[tarif_kpi]), KEEPFILTERS(filtered))​

 


It still didn't work as shown below, though it might be due to the compelxicity of the model:

Slowik131_0-1715581018893.png

 

However, I did find a non elegant solution that works:

 

tarif treatas = VAR sales = SUMMARIZE('Sales', 'Sales'[Date], 'Sales'[Package_ID], 'Sales'[Comm_ID])

VAR filtered = TREATAS(sales, 'Calendar'[Dates], Packages[ID Package], 'Commercial Organisation'[ID Org Com])

RETURN
SUMX (
    VALUES ( 'Commercial Organisation'[ID Org Com] ),
    CALCULATE (
        CALCULATE (
            SUM ( ARPU[TARIF_LOCAL] ),
            KEEPFILTERS ( filtered ),
            FILTER ( 'Commercial Organisation', [Sales] > 0 ),
            FILTER ( Packages, [Sales] > 0 )
        )
    )
)

 

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

TREATAS is a good approach.  Remember you want to filter by the Comm_ID in Table A

 

Measure = CALCULATE(something from Table B,TREATAS(VALUES(TableA[Comm_ID]),TableB[Comm_ID]))

So something like this?

 

 

tarif treatas 2 = VAR sales = SUMMARIZE('Sales', 'Sales'[Date], 'Sales'[Package_ID], 'Sales'[Comm_ID])

VAR filtered = TREATAS(sales, 'ARPU'[Date], ARPU[ID Package], 'ARPU'[ID Org Com])

RETURN
CALCULATE(SUM(ARPU[tarif_kpi]), KEEPFILTERS(filtered))​

 


It still didn't work as shown below, though it might be due to the compelxicity of the model:

Slowik131_0-1715581018893.png

 

However, I did find a non elegant solution that works:

 

tarif treatas = VAR sales = SUMMARIZE('Sales', 'Sales'[Date], 'Sales'[Package_ID], 'Sales'[Comm_ID])

VAR filtered = TREATAS(sales, 'Calendar'[Dates], Packages[ID Package], 'Commercial Organisation'[ID Org Com])

RETURN
SUMX (
    VALUES ( 'Commercial Organisation'[ID Org Com] ),
    CALCULATE (
        CALCULATE (
            SUM ( ARPU[TARIF_LOCAL] ),
            KEEPFILTERS ( filtered ),
            FILTER ( 'Commercial Organisation', [Sales] > 0 ),
            FILTER ( Packages, [Sales] > 0 )
        )
    )
)

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.