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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

Help with Power Query

Hi,

 

I'm trying to do the following: I have a table with facts and a table with sales rate by province, year and quantity kilograms. I need to calculate a custom column in power query to get the value of the sales rate. Something like this in DAX:

 

Sales Rate
    CALCULATE(
        VALUES(TGRAL[Value]);
        FILTER(
            TGRAL;
            'Fact Merged Queries'[Destino.1] = TGRAL[IdProvincia] &&
            'Fact Merged Queries'[Kilos Volumen ORIGEN] >= TGRAL[DesdeKilos] &&
            'Fact Merged Queries'[Kilos Volumen ORIGEN] <= TGRAL[HastaKilos] &&
            YEAR('Fact Merged Queries'[Fecha Salida]) = TGRAL[IdRateYear]
        )
    )

 

Is there any way to do this in Power Query?

 

Thanks and best regards,

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

HI @Anonymous 

You could use this formula to add a custom column in power query

List.Sum(Table.SelectRows(TGRAL, 

(TGRAL) =>  (Date.Year(TGRAL[IdRateYear]) = [Fecha Salida])
and (TGRAL[IdProvincia]=[Destino.1])
and (TGRAL[DesdeKilos]<=[Kilos Volumen ORIGEN])
and (TGRAL[HastaKilos]>=[Kilos Volumen ORIGEN])

)[Value])

https://docs.microsoft.com/en-us/powerquery-m/table-selectrows

https://docs.microsoft.com/en-us/powerquery-m/list-sum

 

 

Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

HI @Anonymous 

You could use this formula to add a custom column in power query

List.Sum(Table.SelectRows(TGRAL, 

(TGRAL) =>  (Date.Year(TGRAL[IdRateYear]) = [Fecha Salida])
and (TGRAL[IdProvincia]=[Destino.1])
and (TGRAL[DesdeKilos]<=[Kilos Volumen ORIGEN])
and (TGRAL[HastaKilos]>=[Kilos Volumen ORIGEN])

)[Value])

https://docs.microsoft.com/en-us/powerquery-m/table-selectrows

https://docs.microsoft.com/en-us/powerquery-m/list-sum

 

 

Regards,

Lin

 

 

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-lili6-msft

 

Thanks so much for your help. I tried your solution and it works. Now i will decide if do it in DAX or M. 

 

Thanks again and regards. 

If you run into performance issues with that solution, use it on partitions instead: https://www.thebiccountant.com/2017/05/29/performance-tip-partition-tables-crossjoins-possible-power... 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi @ImkeF 

 

Thanks for your answer. I will see the link you posted. 

 

Regards,

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.