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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
hanswittoeck
Helper II
Helper II

add column indicating if there is an entry in another table

Hi there

 

Table DIM_PM_order has the fields

Orderno
startdate

enddate

......

 

Table F_PM_cost_details has fields

Orderno 
materialno

qty

cost

 

I want to add a field in table DIM_PM_order 'HasMaterial' that indicates if there is at least 1 entry in table F_PM_cost_details.

The tables are all directquery tables. 

 

 

any suggestions?

 

thx

1 ACCEPTED SOLUTION
Idrissshatila
Super User
Super User

Hello @hanswittoeck ,

 

if the tables are direct query then they're not stored in power bi, they are retreived on query level so in order to do what you want it's either you need to do it in the source or you do a measure and display it in a table visual.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




View solution in original post

9 REPLIES 9
hanswittoeck
Helper II
Helper II

finally, I went for the measure solution

Ashish_Mathur
Super User
Super User

Hi,

Try this calculated column formula

HasMaterial = calculate(countrows(F_PM_Cost-Details),filter(F_PM_Cost-Details,F_PM_Cost-Details[OrderNo]=earlier(Dim_PM_Order[OrderNo])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you for your assitance Ashish

but unfortunatly i get an error
Function 'CALCULATE' is not allowed as part of calculated column DAX expressions on DirectQuery models.

Hi @hanswittoeck ,
You can try this

 

IsValueInAnotherTable = 
IF(
    NOT(ISBLANK(RELATED(F_PM_cost_details[Orderno]))),
    TRUE,
    FALSE
)

Ensure there is a relatiopnship between two tables

 

 

Best regards,
Albert He


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

v-heq-msft
Community Support
Community Support

Hi @hanswittoeck ,
Thanks to Idrissshatila reply.
You can try this
Sample data
DIM_PM_order

vheqmsft_0-1724899189140.png

 

F_PM_cost_details

vheqmsft_1-1724899201770.png

 

OrdernostartdateenddateHasMaterial

Create a column

 

HasMaterial = 
IF(
    COUNTROWS(
        FILTER(
            F_PM_cost_details,
            F_PM_cost_details[Orderno] = DIM_PM_order[Orderno]
        )
    ) > 0,
    TRUE,
    FALSE
)

 

Final output

vheqmsft_0-1724898820550.png

 

Best regards,
Albert He


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

 

 

thank you for your assistance and elaborate response

 

but in directquery, there are limitations

Function 'COUNTROWS' is not allowed as part of calculated column DAX expressions on DirectQuery models.

Idrissshatila
Super User
Super User

Hello @hanswittoeck ,

 

if the tables are direct query then they're not stored in power bi, they are retreived on query level so in order to do what you want it's either you need to do it in the source or you do a measure and display it in a table visual.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos
Follow me on LinkedIn linkedIn
Vote for my Community Mobile App Idea

Proud to be a Super User!




My intention is to add a calculated column for this

Dear @Idrissshatila The choice for the calculated column is because I cannot change the table designs, and more over, I can think of more possible columns to add as I explore more reporting options.

  • Is there labour involved in the orders?
  •  Where orders planned?
  • did ordes exceed the budget?
  • ...

 

It would be nice to have info like this to filter the orders.

So if i have a technique to add a column, it will help me a lot and simplify my visual creation

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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