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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
DanielSantos78a
New Member

How to get the distinct value of a column

I have one table called 'Disputed_Invoices' and I would like to get only the distinct values of the invoice balance from a specific invoice instead of the grant total of the same invoice. I would like to use a DAX formulat to solve this. No sure if it is possible with time intelligence. I have added a small part of my data set so you can have better visualation. 

DanielSantos78a_0-1695507003889.png

This is my data model view 

DanielSantos78a_1-1695507101465.png

and this is my calendar table

DanielSantos78a_2-1695507141578.png

 

1 REPLY 1
OwenAuger
Super User
Super User

Hi @DanielSantos78a 

It appears that you want a measure that returns the "latest" balance per Invoice Number - is that correct?

Have a read of this DAX Patterns article on semi-additive calculations as it covers this general topic.

 

The specific example from that article that is similar to yours is

Balance LastDateByCustomerEver

 

To implement in your model:

1. Make sure your 'Calendar' table is marked as a date table (see here)

2. Create this measure following the pattern from the DAX Patterns article:

 

Balance LastDateByInvoice =
VAR MaxDate =
    MAX ( 'Calendar'[Date] )
VAR MaxBalanceDates =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE ( Dispute_Invoices, Dispute_Invoices[Invoice Number] ),
            "@MaxBalanceDate", CALCULATE ( MAX ( Dispute_Invoices[Date] ) )
        ),
        'Calendar'[Date] <= MaxDate
    )
VAR MaxBalanceDatesWithLineage =
    TREATAS ( MaxBalanceDates, Dispute_Invoices[Invoice Number], 'Calendar'[Date] )
VAR Result =
    CALCULATE (
        SUM ( Dispute_Invoices[Invoice Balance (Converted)] ),
        MaxBalanceDatesWithLineage
    )
RETURN
    Result

 

This measure will return the sum the "latest" value of Invoice Balance per invoice, as at the maximum date filtered in the 'Calendar' table.

 

Does this work for you?

Please post back if needed 🙂
Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors