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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.