The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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,
Solved! Go to Solution.
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
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
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
User | Count |
---|---|
77 | |
75 | |
36 | |
31 | |
29 |
User | Count |
---|---|
94 | |
80 | |
55 | |
48 | |
48 |