簡體   English   中英

當第二個表中未滿足過濾條件時,表行返回空白

[英]Table Row returning blank when Filtered Criteria not met on 2nd table

我有以下兩個表:

Historical_Data_Tbl:

日期 雲% 風_KM 太陽能_Utiliz 價格
01-1月 0.85 0 0.1 4.5
02-1月 0.85 0 0.1 4.5
03-1月 0.95 15 0 10
04-1月 0.95 15 0 8個
05-1月 0.6 25 0.35 6個
06-1月 0.6 25 0.35 6個
07-1月 0.2 55 0.8 6個
08-1月 0.2 55 0.8 7
09-1月 0.55 10 0.5 5.5
1 月 10 日 0.55 10 0.5 5.5
1 月 11 日 0.28 12 0.6 2個
1 月 12 日 0.28 12 0.6 2個
1 月 13 日 0.1 40 0.9 3個
1月14日 0.1 40 0.9 3個
1月15日 0.33 17 0.7 8個
1 月 16 日 0.01 17 0.95 1個
1 月 17 日 0.01 17 0.95 1個

Forecast_Tbl:

日期 Fcst_Cloud Fcst_Wind Fcst_太陽能 最大雲 Min_Cloud 最大風 最小風 Max_Solar 最小太陽能
1個 0.5 12 0.5 0.7 0.3 27 -3 0.75 0.25
2個 0.8 10 0.1 1個 0.6 25 -5 0.35 -0.15
3個 0.15 15 0.8 0.35 -0.05 30 0 1.05 0.55
4個 0.75 10 0.2 0.95 0.55 25 -5 0.45 -0.05
5個 0.1 99 0.99 0.3 -0.1 114 84 1.24 0.74
6個 0.11 35 0.8 0.31 -0.09 50 20 1.05 0.55

代碼如下:

let

//Read in Historical table and set data types
    Source = Excel.CurrentWorkbook(){[Name="Historical"]}[Content],
    Historical = Table.Buffer(Table.TransformColumnTypes(Source,{
        {"DATE", type date}, {"Cloud%", type number}, {"Wind_KM", Int64.Type}, 
        {"Solar_Utiliz", type number}, {"Price", type number}})),

//Read in Forecast table anda set data types
    Source1 = Excel.CurrentWorkbook(){[Name="Forecast"]}[Content],
    Forecast = Table.Buffer(Table.TransformColumnTypes(Source1,{
        {"Date", Int64.Type}, {"Fcst_Cloud", type number}, {"Fcst_Wind", Int64.Type}, 
        {"Fcst_Solar", type number}, {"Max_Cloud", type number}, 
        {"Min_Cloud", type number}, {"Max_Wind", Int64.Type}, {"Min_Wind", Int64.Type}, 
        {"Max_Solar", type number}, {"Min_Solar", type number}})),

//Generate list of filtered Historical Table for each row in Forecast Table with aggregations
//Merge aggregations with the associated Forecast row
    #"Filtered Historical" = List.Generate(
        ()=>[t=Table.SelectRows(Historical, (h)=> 
                    h[#"Cloud%"] <= Forecast[Max_Cloud]{0} and h[#"Cloud%"]>= Forecast[Min_Cloud]{0}
                and h[Wind_KM] <= Forecast[Max_Wind]{0} and h[Wind_KM] >= Forecast[Min_Wind]{0}
                and h[Solar_Utiliz] <= Forecast[Max_Solar]{0} and h[Solar_Utiliz] >= Forecast[Min_Solar]{0}),
                idx=0],
            each [idx] < Table.RowCount(Forecast),
            each [t=Table.SelectRows(Historical, (h)=> 
                    h[#"Cloud%"] <= Forecast[Max_Cloud]{[idx]+1} and h[#"Cloud%"]>= Forecast[Min_Cloud]{[idx]+1}
                and h[Wind_KM] <= Forecast[Max_Wind]{[idx]+1} and h[Wind_KM] >= Forecast[Min_Wind]{[idx]+1}
                and h[Solar_Utiliz] <= Forecast[Max_Solar]{[idx]+1} and h[Solar_Utiliz] >= Forecast[Min_Solar]{[idx]+1}),
                idx=[idx]+1],
            each Forecast{[idx]} & Record.FromList(
                {List.Count([t][Price]),List.Min([t][Price]), List.Max([t][Price]),
                  List.Modes([t][Price]){0}, List.Median([t][Price]), List.Average([t][Price])}, 
                    {"Count","Min","Max","Mode","Median","Average"})),

    #"Converted to Table" = Table.FromList(#"Filtered Historical", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", 
        {"Date", "Fcst_Cloud", "Fcst_Wind", "Fcst_Solar", "Max_Cloud", "Min_Cloud", "Max_Wind", "Min_Wind", "Max_Solar", "Min_Solar", 
            "Count", "Min", "Max", "Mode", "Median", "Average"}),
    
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Column1",{
        {"Date", Int64.Type}, {"Fcst_Cloud", Percentage.Type}, {"Fcst_Wind", Int64.Type}, {"Fcst_Solar", type number}, 
        {"Max_Cloud", type number}, {"Min_Cloud", type number}, {"Max_Wind", Int64.Type}, {"Min_Wind", Int64.Type}, 
        {"Max_Solar", type number}, {"Min_Solar", type number}, {"Count", Int64.Type}, 
        {"Min", Currency.Type}, {"Max", Currency.Type}, {"Mode", Currency.Type}, {"Median", Currency.Type}, {"Average", Currency.Type}})
in
    #"Changed Type"

這是生成的 output:

日期 Fcst_Cloud Fcst_Wind Fcst_太陽能 最大雲 Min_Cloud 最大風 最小風 Max_Solar 最小太陽能 數數 最小值 最大限度 模式 中位數 平均的
1個 0.5 12 0.5 0.7 0.3 27 0 0.75 0.25 5個 5.5 8個 6個 6個 6.2
2個 0.8 10 0.1 1個 0.6 25 -5 0.35 -0.15 6個 4.5 10 4.5 6個 6.5
3個 0.15 15 0.8 0.35 -0.05 30 0 1.05 0.55 5個 1個 8個 2個 2個 2.8
4個 0.75 10 0.2 0.95 0.55 25 -5 0.45 -0.05 6個 4.5 10 4.5 6個 6.5
6個 0.11 35 0.8 0.31 -0.09 50 20 1.05 0.55 2個 3個 3個 3個 3個 3個

Forecast_Tbl OUTPUT ]( https://i.stack.imgur.com/8ozB2.png )

問題是當一個預測行(例如 output 表中的日期“5”應該是)在歷史 Data.table 的過濾范圍內沒有任何數據點時,它會為整行返回空白。

我想要它做的是在前 10 列中從 Forecast_Tbl 返回原始數據,對於“計數”列顯示“0”(當沒有滿足過濾條件時),並使用前幾行“平均”列值(在本例中為 6.5),當沒有滿足過濾條件時。 下面是我希望表返回的 output:

日期 Fcst_Cloud Fcst_Wind Fcst_太陽能 最大雲 Min_Cloud 最大風 最小風 Max_Solar 最小太陽能 數數 最小值 最大限度 模式 中位數 平均的
1個 0.5 12 0.5 0.7 0.3 27 0 0.75 0.25 5個 5.5 8個 6個 6個 6.2
2個 0.8 10 0.1 1個 0.6 25 -5 0.35 -0.15 6個 4.5 10 4.5 6個 6.5
3個 0.15 15 0.8 0.35 -0.05 30 0 1.05 0.55 5個 1個 8個 2個 2個 2.8
4個 0.75 10 0.2 0.95 0.55 25 -5 0.45 -0.05 6個 4.5 10 4.5 6個 6.5
5個 0.1 99 0.99 0.3 -0.1 114 84 1.24 0.74 0 6.5
6個 0.11 35 0.8 0.31 -0.09 50 20 1.05 0.55 2個 3個 3個 3個 3個 3個

我曾嘗試使用條件 if 函數但未成功。

怎么樣

....
{"Count","Min","Max","Mode","Median","Average"})),

#"Converted to Table" = Table.FromList(#"Filtered Historical", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Column2", each try if Value.Is([Column1], type record ) then [Column1] else null otherwise Record.Combine({Forecast{[Index]}, [Count = 0, Average = #"Added Index"{[Index]-1}[Column1][Average]]})),

#"Expanded Column1" = Table.ExpandRecordColumn(Table.SelectColumns(#"Added Custom",{"Column2"}), "Column2", 
    {"Date", "Fcst_Cloud", "Fcst_Wind", "Fcst_Solar", "Max_Cloud", "Min_Cloud", "Max_Wind", "Min_Wind", "Max_Solar", "Min_Solar", 
     "Count", "Min", "Max", "Mode", "Median", "Average"}),
....

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM