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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors