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
BudMan512
Helper V
Helper V

Missing Tickets

Hey,

I am having trouble figuring out what appears to be a fairly simple report.  Any help would be appreciated.

I have a Sales table containing 3 different batches of delivery tickets.  The Tickets are listed consecutively and should add an increment of 1 to each ticket number.

The object of the report is to identify increments greater than 1 and thus determine missing tickets.

If someone could help with the DAX to determine the differences that would be great.

I also have included a ‘Row Rank’ column (Index) that resets whenever the Batch number changes.  This is so when the Rank is 1, the first Difference value will be zero as seen in the table.

There are only Sales and Date tables in this data.

I know there are multiple topics on this subject already but most of them are much more complex than this or I couldn’t get them to work.

Thanks for your time.

Bud

BudMan512_0-1693513864829.png

 

3 REPLIES 3
vicky_
Super User
Super User

Here's what i've got for the dax:

Diff = 
var previousTicket = CALCULATE(MAX('Table'[Ticket]), ALL('Table'[Ticket]), 'Table'[Ticket] < SELECTEDVALUE('Table'[Ticket]))
var previous = IF(ISBLANK(previousTicket), SELECTEDVALUE('Table'[Ticket]), previousTicket) 
return CALCULATE(SUM('Table'[Ticket]) - previous)

vicky__0-1693532575852.png

 

@vicky_ 

@Greg_Deckler 

Here is a link to the report I need help with. It is in OneDrive.

https://ruralcomputers-my.sharepoint.com/:f:/g/personal/bingraham_rccbi_com/Epxdh6HJSABKtqL8mDdM2sYB...

Below is a screenshot of the report.  It is intended to identify missing invoices.  The first invoice in a Batch should be a zero in the 'Diff' column and subseqent invoices should be the difference between an Invoice number and the previous Invoice number.  Normally the difference should be 1 unless there are missing invoices. You can see in the below screenshot the first two batches are working perfectly and then it breaksdown.  The Measure's DAX is below.

BudMan512_1-1695136996890.png

Diff =
var previousTicket = CALCULATE(MAX('History'[Invoice]), ALL('History'[Invoice]), 'History'[Invoice] < SELECTEDVALUE('History'[Invoice]))
var previous = IF(ISBLANK(previousTicket), SELECTEDVALUE('History'[Invoice]), previousTicket)
return CALCULATE(SUM('History'[Invoice]) - previous)
 
I need the report to calculate the difference between invoices accurately while making the diff for the first invoice of a new batch be zero.  If anyone could help me with this, it would be greatly appreciated.

 

Hi Vicky, 

Here is a screenshot of my real world data.  I have substituted 'History'[HIST_REF_NO] for 'Table'[Ticket] in your script.  As you can see, the calculation starts out fine but soon goes off the rails. I wonder if you see what the issue might be. Thanks for your help.

Bud

BudMan512_0-1693583447770.png

 

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.