The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event! Join us in Stockholm, Sweden from September 24-27, 2024.
2-for-1 sale on June 20 only!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the June 2024 Power BI update to learn about new features.
User | Count |
---|---|
99 | |
93 | |
81 | |
63 | |
56 |
User | Count |
---|---|
248 | |
123 | |
111 | |
78 | |
74 |