The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi - I'm really hoping that I can get some help here. I've been banging my head against the wall a while trying to figure this out. Please go easy on me - I'm very new to DAX (or any kind of coding...).
I would like to get the Latest Invoice column to put the phrase "Latest Invoice" into a corresponding row when it's found that that row's invoice is the latest for a particular Project Number. The hitch here is that sometimes, there will be more than one invoice that occurs on the same date. The way that I've written this DAX is such that it will put "Last Invoice" in both cells, because it is looking at only the date and seeing what it considers to be the 'latest date' in both. What I'd like to happen is for the first uniquely identified Invoice ID to get the 'Latest Invoice' and the other (or the rest, when there are more than 2) to go without a tag. I'm guessing that I need to write a script that stores the Invoice ID when it finds the date to be the latest ... or something?
Here's what I'm using so far:
Written DAX
Thank you! I appreciate any help on this.
Solved! Go to Solution.
@LostinDaxland , Try using below DAX
Latest Invoice =
VAR maxDate =
CALCULATE(
MAX(Trial[Invoice Date]),
ALLEXCEPT(Trial, Trial[Project Number])
)
VAR minInvoiceID =
CALCULATE(
MIN(Trial[Invoice ID]),
ALLEXCEPT(Trial, Trial[Project Number]),
Trial[Invoice Date] = maxDate
)
RETURN
IF(
Trial[Invoice Date] = maxDate && Trial[Invoice ID] = minInvoiceID,
"Latest Invoice",
BLANK()
)
Proud to be a Super User! |
|
Hey @LostinDaxland ,
create a pbix file that contains sample data. I assume you want to create a calculated column; for this reason, a pbix that only contains sample data for a single table is sufficient. Upload the pbix to OneDrive, Google Drive, or Dropbox and share the link.
Please, explain the expected outcome based on the sample data you provide.
Next I do not understand what's wrong with the formula you have, except that it flags to invoices (Invoice ID) as "Latest Invoice", e.g. project A15?
If the "Invoice ID" is not sufficient to identify a "single" latest invoice, then no DAX is able to only flag a single row per project.
If the invoice id is sufficient a two step process will help
Regards,
Tom
Hi @LostinDaxland
You can create from the PQ index column for invoices inside the project using the linked method in the first step :
https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query
The result will look like this:
And the add calculated column using DAX :
The PBIX with my generated example is attached you can follow all the steps.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
@LostinDaxland , Try using below DAX
Latest Invoice =
VAR maxDate =
CALCULATE(
MAX(Trial[Invoice Date]),
ALLEXCEPT(Trial, Trial[Project Number])
)
VAR minInvoiceID =
CALCULATE(
MIN(Trial[Invoice ID]),
ALLEXCEPT(Trial, Trial[Project Number]),
Trial[Invoice Date] = maxDate
)
RETURN
IF(
Trial[Invoice Date] = maxDate && Trial[Invoice ID] = minInvoiceID,
"Latest Invoice",
BLANK()
)
Proud to be a Super User! |
|
Thank you! This worked perfectly!
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
82 | |
63 | |
54 | |
52 |
User | Count |
---|---|
128 | |
115 | |
80 | |
65 | |
63 |