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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
rhiheu
Helper I
Helper I

Sales orders that contain apples Y/N

Hi,

What is the column or measure formula to generate the Y or N in the 'Does the order contain apples' column? Using a DirectQuery model.

OrderIDItemDoes the order contain apples?
001ApplesY
001BrocolliY
002PearsY
002ApplesY
002BananasY
003BananasN
003PearsN
004ApplesY

Thanks for your help.

8 REPLIES 8
wdx223_Daniel
Super User
Super User

NewColumn=IF(COUNTROWS(FILTER(Table,Table[Item]="Apples"&&Table[OrderID]=EARLIER(Table[OrderID])))>0,"Y","N")

Hi, thanks for your reply, unfortunately I get an error when I try that - 'EARLIER/EARLIEST refers to an earlier row context which doesn't exist'.

my code is to create a calculated column, not a measure

if to create a measure, try this

=IF(CALCULATE(COUNTROWS(Table),Table[Item]="Apples",ALLEXCEPT(Table,Table[OrderID]))>0,"Y","N")

Hi, when I tried the original formula as a column, it said 'Function 'COUNTROWS' is not allowed as part of calculated column DAX expressions on DirectQuery models', and the latter formula as a measure it doesn't error when creating it but says 'can't display the visual' when I add it to a table. Sorry I should of mentioned in my original post I'm using Direct Query, I'll add that in now. So I'm not sure if there is a solve for this using DAX, maybe only SQL?

tamerj1
Super User
Super User

Hi @rhiheu 
Please try

contain apples =
IF (
    "Apple"
        IN CALCULATETABLE (
            VALUES ( 'Table'[Item] ),
            ALLEXCEPT ( 'Table', 'Table'[OrderID] )
        ),
    "Y",
    "N"
)

Hi @tamerj1, thanks for your reply. I've inputted that formula and it doesn't error, but then when I try and add it to my table it says 'Can't display the visual' - I'm using a Direct Query model if that makes a difference?

@rhiheu 
If you are creating a measure, then please clarify the existing filter context.

Hi, If I use your formula for a column it says 'Function 'CONTAINSROW' is not allowed as part of calculated column DAX expressions on DirectQuery models' which is odd since 'CONTAINSROW' is not actually in the formula.

Re: filter context, I'm not sure if I understand the question sorry - I have a date filter applied, but I want this formula to ignore all filters.

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.