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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Inteq
New Member

Considering sales date as a criteria - relation many to many

 

Hello, 

I have 2 months of data. I try to filter sales by type of client. The problem is type of client type can be different each month as per below table (example) relation many to many.

 

Inteq_4-1671138689340.png

Inteq_6-1671138959815.png

When I try to visualize this data in the table I get incorrect values e.x. For Oct 2022, Type of Client = 1 I get value of 600 because Client 2 has Client Type = 1 in Nov 2022.

Inteq_8-1671139304120.png

I would like to create a measure that consider 'type of client' for value month.  

any tips are welcomed.

 

Thank you in advance.
Inteq

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

I would highly recommend to rewrite your model to this:

sturlaws_0-1671183934671.png

 

Your current model with many-to-many connections and bi-directional filtering will make it quite hard to construct even the simplest measures(which obviously is the reason you have posted your question).

To modify your model, open Transform Data/Power Query, and merge Sales with ClientType on ClientName and Date. This will add client type to your sales table. As the the ClientType-table does not contain any other interesting information, it is not strictly neccessary to keep it, but it does not harm either.

Now you can get your desired output like this:

sturlaws_1-1671184531239.png

 

 

View solution in original post

3 REPLIES 3
sturlaws
Resident Rockstar
Resident Rockstar

I would highly recommend to rewrite your model to this:

sturlaws_0-1671183934671.png

 

Your current model with many-to-many connections and bi-directional filtering will make it quite hard to construct even the simplest measures(which obviously is the reason you have posted your question).

To modify your model, open Transform Data/Power Query, and merge Sales with ClientType on ClientName and Date. This will add client type to your sales table. As the the ClientType-table does not contain any other interesting information, it is not strictly neccessary to keep it, but it does not harm either.

Now you can get your desired output like this:

sturlaws_1-1671184531239.png

 

 

sturlaws
Resident Rockstar
Resident Rockstar

Hi, @Inteq,

could you provide a table displaying the desired outcome? And could you also provide a screen shot of your data model?

 

Assuming you have no relationship between you tables, you can use this measure:

Measure1 =
VAR _clientType =
    CALCULATE ( SELECTEDVALUE ( ClientType[Type of client] ) )
VAR _clientsFromType =
    CALCULATETABLE (
        VALUES ( ClientType[ClientName] ),
        FILTER ( ClientType, ClientType[Type of client] = _clientType )
    )
VAR _month =
    CALCULATE ( SELECTEDVALUE ( ClientType[Date] ) )
RETURN
    SUMX (
        CALCULATETABLE (
            ClientValue,
            FILTER (
                ClientValue,
                CONTAINS ( _clientsFromType, ClientType[ClientName], ClientValue[ClientName] )
                    && ClientValue[Date] = _month
            )
        ),
        ClientValue[ValueCol]
    )

 

but this is rather complex for such a simple task, you would be able to write a much simpler statement if your model your data properly

 

Cheers,
Sturla

 



If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

@sturlaws Thank you for the answer. My model below

Inteq_0-1671173148055.png

 

 

Output table should look like 

Inteq_2-1671169439102.png

Kind Regards,
Paweł

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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