简体   繁体   English

Dax 基于 2 列生成系列

[英]Dax Generate series based on 2 columns

I am trying to analyse energy consumption using rolling 365 day values and using assumptions and averages to get daily usage, the more reads the more accurate the assumptions become.我正在尝试使用滚动 365 天的值并使用假设和平均值来分析能源消耗以获取每日使用量,读取越多,假设就越准确。 I have the data set calculated but now its putting it into a analysable table.我计算了数据集,但现在将其放入可分析的表中。

Dataset数据集

MPAN MPAN Current_Supplier Current_Supplier EAC选管会 EAC_EFD EAC_EFD Days Applicable适用天数 0 0
ID1 ID1 TGPL TGPL 96.7 96.7 22/05/2021 22/05/2021 365 365 0.26 0.26
ID1 ID1 TGPL TGPL 28009.9 28009.9 26/11/2021 26/11/2021 188 188 148.74 148.74
ID1 ID1 TGPL TGPL 30771.2 30771.2 23/05/2022 23/05/2022 178 178 16.61 16.61
ID2 ID2 TGPL TGPL 191.9 191.9 22/05/2021 22/05/2021 365 365 0.53 0.53
ID2 ID2 TGPL TGPL 217.9 217.9 26/08/2021 26/08/2021 96 96 0.8 0.8
ID2 ID2 TGPL TGPL 118.1 118.1 26/11/2021 26/11/2021 92 92 -0.56 -0.56
ID2 ID2 TGPL TGPL 38 38 25/02/2022 25/02/2022 91 91 -0.35 -0.35
ID2 ID2 TGPL TGPL 18.2 18.2 23/05/2022 23/05/2022 87 87 0.3 0.3

Column "0" is Daily usage “0”列是每日使用量

So I have loaded it into Power BI as is and i want to generate a second table where I have column 1 showing the "MPAN" repeating as many times as the "Days Applicable" and column 2 showing the "EAC_EFD" (in a generate series with an increment of 1) and finally a "0" column (AKA daily usage) which will repeat like the MPAN as exampled below in an excel example with notes.因此,我已将其按原样加载到 Power BI 中,并且我想生成第二个表,其中第 1 列显示“MPAN”重复与“适用天数”一样多次,第 2 列显示“EAC_EFD”(在生成系列(增量为 1),最后是“0”列(AKA 日常使用),它将像 MPAN 一样重复,如下面的 excel 示例中的示例所示。

所需的输出但在 Power BI 表中

I've only been using BI for 2 month now so I'm fairly amateur at the whole thing so if there's a different or more efficient way of doing this let me know.我现在只使用 BI 2 个月,所以我对整个事情都相当业余,所以如果有不同或更有效的方法,请告诉我。 Organising it in Python/PHP or a different Code/format is something I could be also interested in doing before I dump it to BI (assuming what I want to do cant be done) so its a wide open one.在我将它转储到 BI 之前,我可能也有兴趣用 Python/PHP 或其他代码/格式组织它(假设我想做的事情无法完成),所以它是一个开放的。

Thanks Ethan谢谢伊森

Simply add a column that is a list of all numbers <= [Days Applicable] then "Expand to new rows" on the list, like this:只需添加一个列,该列是所有数字 <= [Days Applicable] 的列表,然后在列表中“扩展到新行”,如下所示:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8nQxVNJRsjTTMwdSxmamQFLPyEwpVgcmZWRhYGCpZwlkGVpYgEgTCz1zE6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [MPAN = _t, EAC = _t, #"Days Applicable" = _t, Usage = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"MPAN", type text}, {"EAC", type number}, {"Days Applicable", Int64.Type}, {"Usage", type number}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Day", each {1..[Days Applicable]}),
    #"Expanded Days" = Table.ExpandListColumn(#"Added Custom", "Day")
in
    #"Expanded Days"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM