Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I’m struggling with a DAX query/concept –
I have three Entities that have relationships between them: (Account 1:M Opportunity 1:M Opportuntity Lines)
I’m trying to accomplish the same thing in DAX as I would in SQL –
SELECT A.name, OL.productline, MAX(O.createdon) [Oldest AX Opportunity] FROM dbo.account A LEFT OUTER JOIN dbo.opportunity AS O ON O.accountid = A.accountid LEFT OUTER JOIN dbo.opportunitylineitem AS OL ON OL.opportunityid = O.opportunityid WHERE OL.productline = 'AX' GROUP BY A.name, OL.productline;
My first attempt to replicate this in DAX was:
Includes AX = NOT ISEMPTY ( CALCULATETABLE ( 'Opportunity Line Items', 'Opportunity Line Items'[Product Line] = "AX" ) )
Oldest AX Opportunity = CALCULATE ( FIRSTDATE ( Opportunities[Created On] ), FILTER ( Opportunities, Opportunities[Includes AX] = TRUE () ) )
Oldest AX Opportunity = CALCULATE ( FIRSTDATE ( Opportunities[Created On] ), FILTER ( Opportunities, Opportunities[Includes AX] = TRUE () && Opportunities[Account (Value)] = Account[AccountId] ) )However I get this error when I attempt to use it:
I've a explored couple of dozen questions/soluions here and I've read and re-read the post from SQL BI on Context Translation but I don't seem to be connecting the dots on where my approach to the query is going wrong. (I won't bore you with the multiple variations of nesting 'Calculate' or Filters that I've tried without success.)
Any suggestions on where to revise my thinking on this?
Thanks,
Scott.
Solved! Go to Solution.
The formula is actually working - however at some point with earlier tests, the column on my table (apparently) became corrupt and almost no formula would resolve without throwing an error -
The solution was to delete the column and paste the identical code (from 2.2) into a new column.
That's three hours of my life I won't get back...
A colleague, Jarid Mckenzie, suggested this alternative / improvement which should avoid some other challenges in later iterations, but so far both versions are working for me.
First Op = CALCULATE ( MIN ( Opportunities[Created On] ), FILTER ( ALL ( Opportunities ), Opportunities[Account (Value)] = EARLIER ( Account[AccountId] ) && Opportunities[Includes AX] ) )
The formula is actually working - however at some point with earlier tests, the column on my table (apparently) became corrupt and almost no formula would resolve without throwing an error -
The solution was to delete the column and paste the identical code (from 2.2) into a new column.
That's three hours of my life I won't get back...
A colleague, Jarid Mckenzie, suggested this alternative / improvement which should avoid some other challenges in later iterations, but so far both versions are working for me.
First Op = CALCULATE ( MIN ( Opportunities[Created On] ), FILTER ( ALL ( Opportunities ), Opportunities[Account (Value)] = EARLIER ( Account[AccountId] ) && Opportunities[Includes AX] ) )
How would I retrieve a name based on this earliest date ? This column would only calculate the earliest date. I'm basically trying to do any "order by" on a date field, and get the corresponding Name. Any thoughts on how your query below could be tweaked to achieve that In that column
But How do you actually get the Name in that column.
First Op = CALCULATE ( MIN ( Opportunities[Created On] ), FILTER ( ALL ( Opportunities ), Opportunities[Account (Value)] = EARLIER ( Account[AccountId] ) && Opportunities[Includes AX] ) )
This gets you the earliest date. I'm trying to retrieve the Name field of that Earliest opportunity. Any thoughts on how i could do that ?
User | Count |
---|---|
125 | |
106 | |
99 | |
63 | |
62 |
User | Count |
---|---|
135 | |
116 | |
101 | |
71 | |
61 |