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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Gazsim44
Helper III
Helper III

Add 'Order Raised' column

Hi, I have a report I am building which in basic form consists of a Job No, Invoice No and Invoice Date. There can be several invoice's on one job and then also several dates etc.

 

Is there a way I can add an additional column in either Power Query or as a calculated column to indicate in which order an invoice was raised per these three parameters? My table in essence would then look per below with the Order column being the additional added element.

 

Thanks

 

Job No.Invoice No.Invoice Date.Order Raised
1234567866678801/01/20201
1234567866678902/02/20202
9876543255552103/02/20201
9876543255552503/02/20203
9876543255552203/02/20202
1011121322263514/01/20202
1011121322263413/01/20201
1 ACCEPTED SOLUTION
Anonymous
Not applicable

To order on dates first, invoice number second:

 

[Order Raised] =
COUNTROWS (
    FILTER (
        ALL ( 'Table' ),
        'Table'[Job No.] = EARLIER ( 'Table'[Job No.] )
            && (
                'Table'[Invoice Date.] < EARLIER ( 'Table'[Invoice Date.] )
                    || (
                        'Table'[Invoice Date.] = EARLIER ( 'Table'[Invoice Date.] )
                            && 'Table'[Invoice No.] <= EARLIER ( 'Table'[Invoice No.] )
                    )
            )
    )
)

 

View solution in original post

10 REPLIES 10
judspud
Solution Supplier
Solution Supplier

Hi @Gazsim44 

 

The following calculate column formula will work

 

Order Raised = VAR job = Table[Job No.]
var invoice = Table[Invoice No.]
return
CALCULATE(COUNTROWS(Table),FILTER(all(Table),STable[Job No.]=job && Table[Invoice No.]<=invoice))

 

Thanks,

George

Anonymous
Not applicable

Hi,

 

Calculated column should do the job. If the order is based on invoice number, something like this:

[Order Raised] =
COUNTROWS (
    FILTER (
        ALL ( 'Table' ),
        'Table'[Job No.] = EARLIER ( 'Table'[Job No.] )
            && 'Table'[Invoice No.] <= EARLIER ( 'Table'[Invoice No.] )
    )
)

 

Hi & many thanks, 

 

This works fine but doesnt take into account the date? This does need to factored in before the invoice number as there are different sequences of numbers (for credit notes etc). 

 

Sorry I should have stated this at the beginning, 

 

Thanks again, 

Hi @Gazsim44 

 

Please see updated code to include the dates

 

Order Raised = VAR job = Table[Job No.]
VAR InvoiceDate = Table[Invoice Date]
VAR invoice = Table[Invoice No.]
return
CALCULATE(COUNTROWS(Table),FILTER(all(Table),STable[Job No.]=job && Table[Invoice Date]<= InvoiceDate && Table[Invoice No.]<=invoice))

 

Hope this helps

 

Thanks,

George

Anonymous
Not applicable

To order on dates first, invoice number second:

 

[Order Raised] =
COUNTROWS (
    FILTER (
        ALL ( 'Table' ),
        'Table'[Job No.] = EARLIER ( 'Table'[Job No.] )
            && (
                'Table'[Invoice Date.] < EARLIER ( 'Table'[Invoice Date.] )
                    || (
                        'Table'[Invoice Date.] = EARLIER ( 'Table'[Invoice Date.] )
                            && 'Table'[Invoice No.] <= EARLIER ( 'Table'[Invoice No.] )
                    )
            )
    )
)

 

Many thanks! 🙂

Hi George, 

 

Thanks but doesnt seems to be quite right in terms of the results. Let me give you a live example based on this calculation;

 

Many thanks

 

Invoice No.Invoice Date.Job No.Order (based on calculated column) Correct Order
5920268208/11/19802690xxxx33
5214277807/11/19802690xxxx11
5214301408/11/19802690xxxx22
5214812305/12/19802690xxxx34
5920318105/12/19802690xxxx55

 

Hi @Gazsim44 

 

This appears to be an issue with the invoice numbers as the invoice number is higher but the invoice date is before.

 

What logic do you have around the invoice numbers for the different types? i.e. credit notes etc

 

Thanks,

George

 

Pragati11
Super User
Super User

Hi @Gazsim44 ,

 

Can you please elaborate on the logic you want your "Order Raised" column to be calculated?

In the table screenshot, it is confusing. Why there is "1" appearing three times in "Order Raised" column?

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Hi Pragati, 

 

The logic should be that following the job number (being the unique identifier for each file) the next column to look at would be invoice date as naturally anything raised for example on 1st Feb comes before 2nd Feb and so on.

 

To then be able to identify which invoice comes first if we have more than one raised on a single day we would then need to take into account the invoice number. These are issued in sequential invoice number so for example 111222 comes before 111223 and so on, 

 

Hope this helps?

 

Thanks

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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