Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Dear All,
I would like to ask for your help.
I have in my Power BI Desktop two table (tankolas, jaratok). (they are realted to trips and consumptions)
From this two table I would like to create a new table, whitch special criterieas.
In Mysql the query is working but I´m not fit to convert it to DAX or to Power Query.
Is there any possibility if somebody could help me to convert it:
drop table if exists `liter_per_km_table`
;
create table `liter_per_km_table` (
`jaratszam` varchar(255) default null,
`gfrsz` varchar(255) default null,
`kml` double default null,
`kmh` double default null,
`liter` double default null,
`kmdiff` double default null,
`lpkm` double default null,
key `idx_gfrsz_kml_kmh` (`gfrsz`,`kml`,`kmh`)
) engine=innodb default charset=utf8
;
insert into liter_per_km_table
(select
t.JARATSZAM as jaratszam,
t.gfrsz as gfrsz,
tprev.`KM_ALLAS` as kml,
t.km_ALLAS as kmh,
t.liter as liter,
(
t.km_allas - ifnull(tprev.km_allas, 0)
) as kmdiff,
(
t.liter / (
t.KM_ALLAS - ifnull(tprev.km_allas, 0)
)
) as lpkm
from
(select
t.*,
(select
t2.`KM_ALLAS`
from
tankolas t2
where t2.`GFRSZ` = t.`GFRSZ`
and t2.`KM_ALLAS` < t.`KM_ALLAS`
and t2.JOGCIM <> 'Adblue'
order by t2.`KM_ALLAS` desc
limit 1) as prev_KM_ALLAS
from
tankolas t
where t.`JOGCIM` <> 'Adblue') t
left join tankolas tprev
on tprev.GFRSZ = t.GFRSZ
and tprev.`KM_ALLAS` = t.prev_KM_ALLAS and tprev.JOGCIM <>'Adblue'
where t.`JOGCIM` <> 'Adblue')
;
--
-- Query
--
select
r.jaratszam,
r.gfrsz,
r.ind_km,
r.erk_km,
lpkm_mx.kml,
lpkm_mx.kmh,
lpkm_mx.liter,
lpkm_mx.kmdiff,
round(lpkm_mx.lpkm, 3) as lpkm,
greatest(0, least(r.erk_km, lpkm_mx.kmh) - greatest(r.ind_km, lpkm_mx.kml)) as used_km,
round(greatest(0, least(r.erk_km, lpkm_mx.kmh) - greatest(r.ind_km, lpkm_mx.kml)) * lpkm_mx.lpkm, 3) as used_liter
from
jaratok r
inner join liter_per_km_table lpkm_mx
on r.`erk_km` > lpkm_mx.`kml`
and r.`ind_km` < lpkm_mx.`kmh`
and r.gfrsz = lpkm_mx.gfrsz
order by r.gfrsz, r.`IND_KM`
;
Thank you for your help.
Best regards
Feri
@viferenc Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
86 | |
81 | |
53 | |
37 | |
35 |