Forum Discussion
Direct Query First and Last Dates
- 8 years ago
Then we need to create another new measure to calculate the count of productId.
Count ProductId = CALCULATE ( COUNTROWS ( PowerBiTable1 ), FILTER ( ALL ( PowerBiTable1 ), PowerBiTable1[ProductId] = MAX ( PowerBiTable1[ProductId] ) ) )And the final measure will be:
Identifier = IF ( PowerBiTable1[Count ProductId] = 1, "Unique", IF ( MIN ( PowerBiTable1[TransactionDate] ) = PowerBiTable1[FirstTransactionDate], "First", IF ( MAX ( PowerBiTable1[TransactionDate] ) = PowerBiTable1[LastTransactionDate], "Last", BLANK () ) ) )Thanks,
Xi Jin.
Hi v-xjiin-msft
Thank you so much for getting back to me.
Your solution works perfectly. However I have encountered an issue, that I hope you can help me with.
I never realised that I was excluding products that has only been sold once.
Can we edit the measures to say if the product ID appears once then its “Unique” if it appears Multiple times the first transaction (based on date) should say “first” and the last transaction (based on date) should say “Last”
Thanks in advance,
Boycie92
Then we need to create another new measure to calculate the count of productId.
Count ProductId =
CALCULATE (
COUNTROWS ( PowerBiTable1 ),
FILTER (
ALL ( PowerBiTable1 ),
PowerBiTable1[ProductId] = MAX ( PowerBiTable1[ProductId] )
)
)And the final measure will be:
Identifier =
IF (
PowerBiTable1[Count ProductId] = 1,
"Unique",
IF (
MIN ( PowerBiTable1[TransactionDate] ) = PowerBiTable1[FirstTransactionDate],
"First",
IF (
MAX ( PowerBiTable1[TransactionDate] ) = PowerBiTable1[LastTransactionDate],
"Last",
BLANK ()
)
)
)Thanks,
Xi Jin.
- Boycie928 years agoResolver I
Hi v-xjiin-msft
Thanks for the help.
I have having an issue with the Identifier measure.
MIN ( PowerBiTable1[TransactionDate] ) = PowerBiTable1[FirstTransactionDate],
"First",
IF (
MAX ( PowerBiTable1[TransactionDate] ) = PowerBiTable1[LastTransactionDate],I get a red line at the bold parts of you formula. I looked at the error message and it says “a single value for column "" cannot be determined”
Any ideas why?
Thanks,
Boycie92
- v-xjiin-msft8 years agoSolution Sage
First, PowerBiTable1 is my sample table name. Please verify that you have replaced it with your own source table.
Then since you are using the Direct Query data mode. So all my sample DAX expressions are used to create measures, not calculated columns. Please verify this.
By the way, if you can share us some screenshots about your report structure like how you define the measures in your scenario. It'll help us more to troubleshoot your issue.
Thanks,
Xi Jin.- Boycie928 years agoResolver I
Hi v-xjiin-msft
It was my fault I was referencing the wrong column.
I have another issue, I wanted to create this (ideally as a column), so I could the create a measure that would not count any rows that did not say “First”. Is there any way I can achieve this since i am now using a measure?
I can use it as a Visual Level filter but i would prefer not to.
Thanks,
Boycie92
- Jon9287 years agoRegular Visitor
Thanks Xi Jin
I tried the code and I am getting the error "Function 'FILTER' is not supported in this context in DirectQuery mode."?