1

I have a excel sheet containing 2 rows. Each row has the data inserted into multiple columns. What I need is to generate a comma separated list based on all the logic if its 08:00 a.m. then 0 if is p.m. then 1 like this:

0,1,0,1,0,0,0,0

On the second row I have the same, but here I can have empty cells, if I have an empty cell, so I should get something like:

0.8,0.8,0.7,0.8,,,,,

enter image description here

Any clue?

2

4 Answers 4

1

For the first row, you can use a combination of TextJoin and Round. Rounding 8 AM down will result in 0, rounding 8 PM will result in 1.

=TEXTJOIN(",",FALSE,ROUND(A1:H1,0))

The second row can be served with

=TEXTJOIN(",",FALSE,A2:H2)

enter image description here

1

If you are happy to get the results as a new file, you can export/save the spreadsheet as a CSV file.

0

Use if formula to convert the first row to 0 and 1, then convert the file to a csv file.

2
  • I have to have the comma separated value in a field
    – VAAA
    Sep 12, 2019 at 0:51
  • What do you mean by field? Sep 12, 2019 at 0:52
0

You can do so using #PowerQuery (available in Excel 2010 and later versions) apart from formula based solution.

The logic is to add the data to the power query editor, use the Replace Values function under the Transform tab to replace 08:00 a. m. with 1 and replace 08:00 p. m. with 0, and then use Merge Columns function under the Transform tab to merge all columns with comma , as the delimiter. The outcome may look like the following. You can load the result to a new worksheet (by default) or create a connection to this query and load it to a specific location but the limitation is that it has to be in a Table.

Power Query

Here is the full power query m code behind the scene for reference only. All functions are performed using built-in functions.

let
    Source = Excel.CurrentWorkbook(){[Name="YourTable"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type any}, {"Column2", type any}, {"Column3", type any}, {"Column4", type any}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","08:00 a. m.",1,Replacer.ReplaceValue,{"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","08:00 p. m.",0,Replacer.ReplaceValue,{"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8"}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Replaced Value1", {{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}}, "en-AU"),{"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8"},Combiner.CombineTextByDelimiter(",", QuoteStyle.None),"Merged")
in
    #"Merged Columns"

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.