Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
SvenJ
Helper III
Helper III

add table column dynamically from csv

Good evening everyone,

 

i have the problem, that i need to add columns to an existing table dynamically to calculate sums. The header is always the same, but the amount of rows and the number "#BWA-Zeile" is different.

 

csv 1
#BWA-ZeileZeilenbeschriftungZeile vonZeile bis
1051Product A10201045
1080Product B10511060
1092Total10801090
1280Costs11001260
1300Revenue10921280
1320Some costs13101312
1330Some incoing13221324
1345Test13001320
1345Teste 213301340
1380final amount13451355

 

 

csv 2
#BWA-ZeileZeilenbeschriftungZeile vonZeile bis
1021Amount10171019
1027Product A10231025
1040Product B10171023
1042Product C10181024
1043Product D10191025
1051Total10401043
1072Costs10611071
1075Revenue10511072
1219some costs12071211
1299Test12431267
1345check10751219
1380final amount13451355

 

At the moment i´m adding and calculating the "rows" like this:

 

 

  #"S1051" = Table.AddColumn(#"Gefilterte Zeilen1", "1051", each if (([BWA Zeile] >= 1020) and ([BWA Zeile] <= 1045)) then[Umsatz Values] else 0),
    #"S1080" = Table.AddColumn(S1051, "1080",  each [1051] -  (if ([BWA Zeile] >= 1051) and ([BWA Zeile] <= 1060)  then [Umsatz Values] else 0)),
    #"S1092" = Table.AddColumn(#"S1080", "1092", each [1080] +  (if ([BWA Zeile] >= 1080) and ([BWA Zeile] <= 1090)  then [Umsatz Values] else 0)),
    #"S1280" = Table.AddColumn(#"S1092", "1280", each if (([BWA Zeile] >= 1100) and ([BWA Zeile] <= 1260)) then [Umsatz Values] else 0),
    #"S1300" = Table.AddColumn(#"S1280", "1300", each [1092] - [1280]),
    #"S1320" = Table.AddColumn(#"S1300", "1320", each  if (([BWA Zeile] >= 1310) and ([BWA Zeile] <= 1312)) then [Umsatz Values] else 0),
    #"S1330" = Table.AddColumn(#"S1320", "1330", each if (([BWA Zeile] >= 1320) and ([BWA Zeile] <= 1324)) then[Umsatz Values] else 0),
    #"S1345" = Table.AddColumn(#"S1330", "1345", each [1300] - [1320] + [1330]),
    #"S1380" = Table.AddColumn(#"S1345", "1380", each [1345] - (if ([BWA Zeile] = 1355) then[Umsatz Values] else 0)),
    #"Geänderter Typ6" = Table.TransformColumnTypes(#"S1380",{{"Umsatz Values", type number},{"1080", type number}, {"1092", type number}, {"1280", type number}, {"1300", type number},{"1320", type number}, {"1330", type number}, {"1345", type number},{"1380", type number},{"1051", type number}}),
    

 

 

 

It means that i need "#BWA Zeile" as the column name and "Zeile von" to "Zeile bis" as a calculation. Any help would be great

3 REPLIES 3
SvenJ
Helper III
Helper III

@AlexisOlson You,re right, that´s the calculation of this, but how can i get it dynamically into the advanced power editor? Some columns have different names, one table has x (amount) rows, the other one has y (amount) rows.

I don't understand what you're trying to do well enough to say. What are all these extra columns for and what are the rules that define how you want them to behave? Why do some have addition/subtraction and others don't?

AlexisOlson
Super User
Super User

I don't quite understand the logic behind all these columns but it seems like you're comparing the first column to the last two a lot and this could be simplified by replacing e.g.

if (([BWA Zeile] >= 1020) and ([BWA Zeile] <= 1045)) then[Umsatz Values] else 0

with column references instead of those hard-coded numbers:

if ([BWA Zeile] >= [Zeile von]) and ([BWA Zeile] <= [Zeile bis]) then [Umsatz Values] else 0

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors