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
Vu_TR
Frequent Visitor

Splitting rows based on condition by ratio.

Hello everyone,

I am having an issue with cost allocation in accounting. I have data table 1 as shown below, and allocation ratios in table 2. How can I automatically transform this into data table 3 based on the ratios in table 2?

I hope to receive everyone's help. Thank you very much.

Vu_TR_0-1687670560651.png

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new table.

 

Jihwan_Kim_0-1687675934704.png

 

 

New Table = 
SUMMARIZE (
    ADDCOLUMNS (
        GENERATE (
            Data,
            FILTER (
                Allocation,
                EOMONTH ( Allocation[Period], 0 ) = EOMONTH ( Data[Date], 0 )
                    && Allocation[Department] = Data[Department]
            )
        ),
        "@AmountXRatio", Data[Amount] * Allocation[Allocation_rate]
    ),
    Data[Date],
    Data[Account],
    Data[Description],
    Allocation[Sub_Department],
    [@AmountXRatio]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

Vu_TR
Frequent Visitor

I had never heard of SQL before, but I will learn it to compare with other methods. Thank you very much for your help.

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

One can write a calculated column formula in Table2 (LOOKUPVALUE() function) to search in 3 columns of Table1 (Date, Department) and bring over the amount from Table1.  Then in Table2, one can simply multiply the 2 columns.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
rbriga
Impactful Individual
Impactful Individual

For the best results, solve it in the query.

If it's a SQL (or SQL-like) source, it would be something like

SELECT
	T1.DATE,
	T1.ACCOUNT,
	T1.DESCRIPTION,
	T2.SUB_DEPARTMENT,
	T1.AMOUNT * T2.ALLOCATION_RATE AS ALLOCATED_AMOUNT
FROM TABLE1 T1
LEFT JOIN TABLE2 T2
	ON DATEADD(MONTH, DATEDIFF(MONTH, 0, T1.DATE), 0) = T2.PERIOD --AND!!!!!!!

But mind that we might be missing another field that tells us to which department each breakdown is relevant.

 

In a non-SQL source, do the same in the query editor.

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!
Vu_TR
Frequent Visitor

I had never heard of SQL before, but I will learn it to compare with other methods. Thank you very much for your help.

Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Splitting rows based on condition by ratio..pbix

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.

Vu_TR
Frequent Visitor

That's great, it worked really well in Power Query. Thank you for your enthusiastic assistance.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new table.

 

Jihwan_Kim_0-1687675934704.png

 

 

New Table = 
SUMMARIZE (
    ADDCOLUMNS (
        GENERATE (
            Data,
            FILTER (
                Allocation,
                EOMONTH ( Allocation[Period], 0 ) = EOMONTH ( Data[Date], 0 )
                    && Allocation[Department] = Data[Department]
            )
        ),
        "@AmountXRatio", Data[Amount] * Allocation[Allocation_rate]
    ),
    Data[Date],
    Data[Account],
    Data[Description],
    Allocation[Sub_Department],
    [@AmountXRatio]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Although DAX functions are more difficult for me to understand than Power Query, they also perform very well. Thank you @Jihwan_Kim so much for your support.

rbriga
Impactful Individual
Impactful Individual

Best practice is to push the tranformations into the source- a native query if possible, or a Query Editor transformation. This means real-time calculations are faster, and the measures simpler.

-------------------------
Data analyst by day, hockey goalie by night.
Did I help? Then please hit that "kudos" or "accept as a solution" button!

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.