Custom Column in Power BI - powerbi

Can someone please help me with custom column code in Power BI Query Editor.
I wish to get a value "Latest" in custom column against "CRTG-0006" as 0006 is the highest number in the column. CRTG-0006 is the latest version of the Program CRTG & CRTG-0001 being the first version of the Program. In future, let's say if I add "CRTG-0007" file in the root folder, Custom Column return value shall be "Latest" for "CRTG-0007" and shall be "null" for "CRTG-0006" and all previous versions of the Program.

Given your layout,
Assume your program and versions column header is Program
Assume your preceding step is #"Changed Step
Then, in the Add Custom Column dialog you can use this formula:
if [Program] = List.Max(#"Changed Type"[Program]) then "Latest" else null
This works because your format is such that simple alphabetical sorting will work. The program name/abbreviation is always the same, and the version number is padded with zero's
By the way, if you have multiple programs in the Program column, I would group by the program base name, and apply the same algorithm in a custom aggregation.

It's a bit hard to tell what you want but you can right click then split the column on - to get the number. You can then convert type to numerical and sort or take the List.Max([ColumnName])

Related

POWER QUERY [Expression.Error] Cannot convert the value null to type Table

SOLVED USING A DIFFERENT APPROACH (see at the end)
I am trying to combine some queries into one by using the Table.Combine() function.
If I explicitly write the name of each query (e. g., Table.Combine({#"Name of query 1", #"Name of query 2"})) and then apply the changes, everything works fine.
However, since I want to make it dynamic, instead of writing a list of names, I pass the function a list of tables generated in a previous step:
So after I get this table, the next step is: = Table.Combine(PreviousStep[Value]). Note that Value is the name of the column that contains the tables. Apparently, by doing so this column of a table containing tables is converted to a list containing tables. This works fine (I can preview the resultset) until I hit that Apply changes button. When I do it, this message pops up:
I had a look at these threads: https://community.powerbi.com/t5/Desktop/We-cannot-convert-the-value-null-to-type-Table/td-p/391064, https://community.powerbi.com/t5/Desktop/We-cannot-convert-the-value-null-to-type-table/m-p/346056, but it didn't work. I've tried other approaches as well.
Further information:
Power BI Desktop version: 2.106.582.0 64-bit (June 2022)
Data source: combining existing queries that come from a single Excel file.
Steps followed to get that list of tables that I pass the Table.Combine() function:
let
Origen = #sections[Section1],
#"Convertido en tabla" = Record.ToTable(Origen),
#"Errores quitados" = Table.RemoveRowsWithErrors(#"Convertido en tabla", {"Value"}),
Personalizado1 = Table.SelectRows(#"Errores quitados", each Text.StartsWith([Name], "COMPRAS Y GASTOS")),
Personalizado2 = Table.Combine(Personalizado1[Value])
in
Personalizado2
I access all the queries I have (with the #sections keyword), convert it to a table, remove possible errors, filter to get the queries I want (the ones starting by "COMPRAS Y GASTOS") and then try to combine the queries).
A DIFFERENT APPROACH
What I wanted to do was merge tables that came from an Excel file, each of them referring to a year (2019, 2020, 2021, 2022). But I also wanted the combined table to update when new sheets were added on Excel (2023, 2024...).
I've tried many different approaches, like generating a dynamic list (from 2019 until the current year)... but for some reason none of them worked, even though the code apparently is correct.
So my new approach has been to create a sufficient amount of Excel sheets for the coming years (that are now empty, but when the new year comes the information will be filled in there), to create the queries referring to those sheets (they return empty tables) and merging those existing (but empty) tables with the ones from 2019-2022. This way, when data from 2023 is filled in in the sheet, the query is updated and it works.
It's a shame I couldn't actually solve the original problem I had, but this approach works.

Sheets, conditional formatting

I am looking to create a conditional formatting function that will highlight "C2:E2" if "E2" > 5000 & "B2" does not contain the word "treasury".
any help would be appreciated!
try on range C2:E:
=($E2>5000)*(NOT(REGEXMATCH(LOWER($B2), "treasury")))
Navigate in top menu to Format -> Conditional formatting
There you can specify range as E2:E29
Use conditional formatting with just one AND formula that refers dynamically to the values of the same row, but different column
AND comparision of the current value
=AND(indirect(address(row();column()-3))<>"Treasury";indirect(address(row();column()))>5000)
This can maybe be simplified, but definitely works with more conditions at once.
Some explanation:
To avoid typing new formulas for each row, we use INDIRECT joined with ADDRESS
column()-3 refers to current column (the one you call formula in) . Have in mind that means for each columns (C->E) you need a different formula that refers to another column for checking if it contains "treasury". In your case you'll need different formulas for column C,D and E. column()-3 works for E, because Treasury is in B column (3 columns earlier from E)
P.S: translating from my native language, so not sure if English UI is the same, but should be intuitive from here.
You'll want a custom Conditional Formatting Rule.
Click in cell C2, then from the menu choose:
Format > Conditional formatting
In the dialog box, set your range:
C2:E29 (or change 29 to whichever row is the last one you want to include in the formatting rule)
Under Format rules > Format cells if..., choose the bottom option from the dropdown menu: "Custom formula is."
In the field below, enter this formula:
=AND(NOT(ISNUMBER(SEARCH("treasury",$B2))),$E2>=5000)
Set your formatting style and click Done.

How to select multiple values from a filter in Google Sheets?

I've got lots of data in a Google sheet (I do not have Excel or Windows as I am on a Chromebook) and I want to use one column to filter out cells which contain two different words. The column of data might contain various values.
Example
Cell 1 Acme - Main - Location
Cell 2 Acme - Secondary - Location
Cell 3 Acme - Location - Main
Sticking with the above example, I would like to use my data filters set at the column headers to only show me cells where it matches Acme and Main.
What is the best way of doing this, please?
I tried using the Text Contains option in the data filter but I'm not sure how to insert both words as something to filter by, it seems to only filter the words exactly how they are typed. So if I type in Acme Main into the filter it will work for some cells which are in that exact order.
if the order of "acme main" combo does not matter you could use:
=REGEXMATCH(A1:A, "Acme(.+)Main|Main(.+)Acme")
if you also want it by any chance case-insensitive use:
=REGEXMATCH(LOWER(A1:A), "acme(.+)main|main(.+)acme")
In the filter options, use this custom formula
=regexmatch(A1:A, "Acme(.+)Main")
and see if that works?
Change column reference to suit.

How to put formula in Data Validation List Excel?

I am creating an excel sheet with following Data Validation drop down list.
NA
Done
(add some formula here)
Basically, i will be able to select either plain text "NA"/ "Done" from the dropdown list. But sometimes, I want the user to be able to calculate some values based on the cell respective to the row selected so, I want to have one formula as a choice inside the data validation dropdown list. Is this possible?
Data Validation List Source
When I click on Formulae option, it should execute the formula with respect to the cells in that Row
But currently, the formula that i put in doesn't execute, instead it will just show the whole formula in the cell when activated.
1)How can i make it so that when i select the formula from data validation list, it will execute it instead of filling up the cell with it?
2)How do i set the formula so that it will be using the cell from the current Row? (for example, if i am using the data validation List in N60, the formula should adapt itself to use the cell (let's say A60?).
I may not be able to help with the second part, but I was seeking an answer to the first and discovered a solution/workaround using Name Manager.
First, in Formula > Name Manager, create a new reference (the "refers to" will contain whatever formula you are wishing to ultimately display in the validation list. For this example, we use the formula reference "=IF($H54=..." and Name it "UniqueName"
Now, we go into Data Validation, Select List, and input the three items we want displayed in the list, with an equals sign preceding our newly named reference: ie. "NA,Done,=UniqueName"
Note: You can't start with the =UniqueName or validation will try to read it all as a formula and fail.
This method will allow the user to display "NA", "Done", or "=UniqueName" in the cell; if "=UniqueName" is selected, the cell itself will interpret this as a formula and execute it accordingly, displaying the results of "=IF($H54=...", or whateverelse you have designated to use as a named formula.
If it's too late for yours, I hope this helps someone else who may face a similar problem.
While I think I know what you're trying to say. Why don't you just use an IF formula to evaluate everything instead of selecting a drop down for every row manually. You already had it partially solved using IF. Just need to add the criteria for a "Done" and an "NA"
=if(A1="date","Done",if(A1<"date","NA",if(something else until you have all your catergories))
Just going to piggyback off of Mark's response.
If you really needed your named formula to be the first selection in the list, you can setup your list with a leading comma like so:
,=UniqueName,NA,Done
That worked out for my use, and there was no null item listed in the Data Validation drop down. Hope that helps!

Aqua Data studio, compare results, column names case-sensitive

Any Aqua Data studio users out here know how to turn off case-sensitivity when comparing results?
e.g. in one Query, column 1 is called "test", in another one it's called "TEST", then Aqua datastudio does not identify these columns when comparing results. How can I turn this off?
I can ignore upper/ lower case in the result set, but not in the column names.
Renaming every column each time manually is a pain. Somebody knows?
For Results Compare, cant you change your SQL Query to the same case, using Upper or using ALIAS for the column name ? I used for e.g. UPPER("category") AS CATEGORY and this solved the problem you are having.
For Schema Compare do the below
Under File->Options, Compare, enable option to Ignore Case
When you perform a Schema Compare, Under Object Alignment, you can select to Ignore Case