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
PijushRoy
Super User
Super User

Two DAX calculated column needed for calculate returning customer series and no of invoice

Hi Team,

I have data like below (from column 1 to 3) and I need to create two calculated column for 4 and column 5

PBIX file attached for sample data and two require column
001.JPG

 

Thanks in Advance




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





1 ACCEPTED SOLUTION

Hi @PijushRoy ,

 

Redo the calculation to:

CUST SERIES = 
VAR MAXINVOICE =
    IF ( Data[Hown Many Invoices] = 1, Data[Index],Data[Index]+ Data[Hown Many Invoices]-1 )
RETURN
    IF (
        Data[Hown Many Invoices] <> BLANK (),
        Data[Invoice_ID] & "-"
            & MAXX ( FILTER ( ALL ( Data ), Data[Index] = MAXINVOICE ), Data[Invoice_ID] )
    )

 

MFelix_0-1668528250762.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

16 REPLIES 16
MFelix
Super User
Super User

Hi @PijushRoy ,

 

Try the following two codes:

Hown Many Invoices = 
VAR temptable =
    TOPN (
        1,
        FILTER (
            Data,
            Data[Unique_Cust] <> 1
                && Data[Index] > EARLIER ( Data[Index] )
        ),
        Data[Index], ASC
    )
VAR Row_Number =
    MINX ( temptable, Data[Index] ) - Data[Index]
VAR TotalRows =
    MAXX ( Data, Data[Index] )
RETURN
    IF (
        Data[Unique_Cust] <> 1,
        IF ( Row_Number > 0, Row_Number, TotalRows - Data[Index] + 1 )
    )


MFelix_1-1668518915608.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix 
Small mismatch
It is taking Index 4 rows Invoice number inplace of Index 25 Invoice no
0012.JPG




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





Hi @PijushRoy ,

 

Redo the calculation to:

CUST SERIES = 
VAR MAXINVOICE =
    IF ( Data[Hown Many Invoices] = 1, Data[Index],Data[Index]+ Data[Hown Many Invoices]-1 )
RETURN
    IF (
        Data[Hown Many Invoices] <> BLANK (),
        Data[Invoice_ID] & "-"
            & MAXX ( FILTER ( ALL ( Data ), Data[Index] = MAXINVOICE ), Data[Invoice_ID] )
    )

 

MFelix_0-1668528250762.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



vanessafvg
Super User
Super User

@PijushRoy  you haven't provided more information

 

i haven't done all of it but is this what you are looking for?  please confirm - you haven't give enough information, you havent provided an expected solultion.  If you need help you do need to provide a clear set of what is expected.

 

vanessafvg_0-1668517695091.png

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@vanessafvg 
Can you please share the pbix, when I applied calcualtion, I am not getting same data as you mentioned in image.




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





it changed thats probably why.  Its still not perfect  however but i am unsure of what you want so please clarify with the exact results.

 

Get UniqueCust =
VAR selinvoiceid =
SELECTEDVALUE ( Data[Invoice_ID] )
VAR mininvoiceid =
CALCULATE ( MIN ( Data[Invoice_ID] ) )
VAR maxindex =
CALCULATE (
MIN ( Data[Index] ) - 1,
ALL ( data ),
Data[Invoice_ID] > mininvoiceid
&& Data[Unique_Cust] > 1
)
VAR minindex =
CALCULATE (
MAX ( Data[Index] ),
ALL ( data ),
Data[Index] < maxindex
&& Data[Unique_Cust] > 1
)
VAR firstinvoiceid =
CALCULATE ( MIN ( Data[Invoice_ID] ), ALL ( Data ), Data[Index] = minindex )
VAR maxinvoiceid =
CALCULATE ( MAX ( Data[Invoice_ID] ), ALL ( data ), Data[Index] = maxindex )
VAR result =
IF ( selinvoiceid = maxinvoiceid, selinvoiceid, firstinvoiceid ) & "-"
& IF ( ISBLANK ( maxinvoiceid ), mininvoiceid, maxinvoiceid )
RETURN
result





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Ashish_Mathur
Super User
Super User

Hi,

In a simple MS Excel file, please show the expected result with formulas/comments.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
vanessafvg
Super User
Super User

its not perfect but its a something to work with i needs more tweaking

 

Get UniqueCust =
VAR mininvoiceid =
MIN ( Data[Invoice_ID] )
VAR maxindex =
IF (
SUM ( Data[Index] ) > 1,
CALCULATE (
MIN ( Data[Index] ) - 1,
ALL ( data ),
Data[Invoice_ID] > mininvoiceid
&& Data[Unique_Cust] > 1
),
BLANK ()
)
VAR maxinvoiceid =
CALCULATE ( MAX ( Data[Invoice_ID] ), ALL ( data ), Data[Index] = maxindex )
RETURN
mininvoiceid & "-"
& IF ( ISBLANK ( maxinvoiceid ), mininvoiceid, maxinvoiceid )





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@vanessafvg 
Thanks for your help, however it is not working and not shoiwng correct result.




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





as i said it needs tweaking.  however agree providing more information might be useful as the in expected result for each row.





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




PijushRoy
Super User
Super User

Hi,

Any help please




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





Thank you all for support 
@MFelix @vanessafvg @rsbin @Ashish_Mathur 




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





@PijushRoy ,

Please refer to modified pbix attached.

Edit: 

Just realized I didn't follow through with all your requirements.  Hoping though you can see the pattern and make the necessary modifications.

Trust you will be able to follow the logic.

Any questions, please ask.

Best Regards,

Hi @rsbin 

Thanks for your help, but it is not working
Series ending value is not matching
Invoice count number is not correct for all
001.JPG




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





@PijushRoy ,

 I thought the logic of capturing the first 3 characters would work, but unfortunately

 this appears not to be the case.

Looks like another approach or method will be required.

Might be worthwhile closing this thread and start a new one.

Revised file attached.  Gets a little closer but still instances where logic is incomplete

Hi @rsbin 

I need to solve this urgently, I am also trying. Can you please try and let me kwon, It will great help for me.




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





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.