Thursday, 24 July 2025

Excel's yellow triangles when imports matches no exports

 

If you've ever seen a yellow triangle here the chances are it might have taken you a while to fix it. When I asked Co-Pilot it was useless.

For me, I think the error came about because:
1. I had changed a query name.
2. That query fed a Pivot table a table or something which was on a tab I then deleted.

Something like that anyway. I went all around the house trying to figure it out.

In the end the fix was to right click on the offending query and select "Load to". you'll get this box


For me the error came about partly because I didn't want this connection to appear as a Table in the first place, (but I'm still figuring out how best to keep manage which tables you want to appear in the front end of Excel and which you don't. PowerBI has a handy feature for this but Excel is a bit of a nightmare. At least at the moment it does).

Anyway, as a result, I found that if I unticked "Add this data to the Data Model" when I had already selected "Only Create Connection" and OK'd it, then when I went back into this and re-ticked it, the error went away.

I'd advise caution because if your queries are tied together in a complicated configuration then it might cause knock-on issues. So particularly if you're taking this spreadsheet on from someone else check thoroughly that it's not going to mess anything else up. 

And if you're with Microsoft & reading this, then please can we have the same chance to select which queries do and do not appear in the front end of Excel after we're done with them in Power Query.

Thursday, 26 June 2025

A super easy grid for Power BI using DAX & SVG

The grid function in PowerBI is woeful.

Mine currently doesn't work and I haven't even bothered to investigate it because it's so poor when it does work.

But this week I taught myself how to create SVG images using SAX and the HTML Content lite custom visual – which is really straightforward. I'm not sure why I put it off for so long – and it occurred to me that one useful thing to build was a grid which I could easily set up anytime I needed that extra bit of precision. 

This one uses DAX so you're already familiar with a lot of it. The variables at the top are the gap between lines the height and width of your desire screen (the latter two are defaulted to the standard screen dimensions in PowerBI) and you can easily adjust the gap width. I'll give the code first and then explain it

SVG grid 1 =
VAR gap = 40
VAR gridwidth = 1280
VAR gridheight = 720
VAR tablex = ADDCOLUMNS(
GENERATESERIES(0, gridheight, gap),"Label", "<polyline points='0, " & ([Value] - gap)  & " " & gridwidth & "," & ([Value] - gap) & "' stroke='grey' stroke-width='1' fill='none'/>"   )

VAR tabley = ADDCOLUMNS(
GENERATESERIES(0, gridwidth, gap),"Label", "<polyline points='" & ([Value] - gap) & ", 0 " & ([Value] - gap) & "," &gridheight & "' stroke='grey' stroke-width='1' fill='none'/>"   )

RETURN
"<svg viewBox='0 0 " &gridwidth & " " & (gridheight - 10) &"' opacity='0.5'>" &
CONCATENATEX(
    FILTER(UNION(tablex,tabley), [Value]<>0 && [Value] <> gap),
    [Label],UNICHAR(10)
) & "</svg>"

You use this to create a measure and then get the HTML Content Lite app from the custom visual store and ad the measure into the Values well. You'll need to extend the box to the full extent, remove padding in the Format pane but you should be good to go.

Essentially what this does is 

Use GENERATESERIES() to create values from ) to the width of your screen and then...
Use ADDCOLUMNS() to  convert that into a table where each line has increased the value by your chosen gap then...
Use UNION to join the values of the y lines to the value of the x lines then...
Use CONCATENATE() to turn that into a lump of text
Finally you add the required code to the start and end.

If you're unsure how it works, you can progress it through DAX viewer or by viewing the measure itself.

To make it super easy to recall this, I also saved it as a text file and added a hotstring in AutoHotKey so now I simply got to PowerBI, create a measure, type "gridx" and then add that to the visual.

Friday, 13 June 2025

Tips for data cleansing & whether to use a consultant

I got asked a question the other day about data cleansing from a relatively small organisation, who is wondering about whether or not to use a consultant and if so, how. I figured others here might also be facing this issue so I thought it was worth reposting my answer here. 

I think the first thing I'd say is to make sure you properly listen to the data experts within your team. It's amazing how many managers/teams/organisations don't really do this. Guess how well that ends?

There are two issues in particularly to engage with your team on, and I'd really recommend discussing them separately to begin with. 

The first is to really get to the heart of what data cleansing is required. The term "data cleansing" covers a multitude of sins and the issues are complicated because no large system will ever be 100% clean. You need to draw out what the specific issues are and get some kind of of order of significance. For example:

  • Is it that there are multiple records per person? or...
  • Is it that address data is old and out of date? or...
  • Is it the formatting of data poor? or...
  • Are there are lots of mistakes such as badly typed email addresses; or...
  • Is it that the underlying structure is all wrong for what you are trying to achieve; or... 
  • Is data stored inconsistently – in different places for different records. etc.

Get a really good sense of that, the size of each issue and the degree to which it's stopping you to reach your goals before choosing / talking to a consultant.

The other issue to engage them on is how they feel about the task of taking on this data cleanse versus getting someone else in. Would they welcome the help or is this something which if other demands on them were to be stemmed for a while, or with a bit more resource, temps etc. they could execute themselves? I think these things are best discussed separately, at least initially, because for me at least, the concerns about the second set of questions can hamper getting to bottom of the first question.    

The other thing which is also worth thinking about both with your team(s) and any potential consultant is how will you shut the back door? That is, how will you ensure your data doesn't get messy as quickly again? Again some questions to ponder:

  • What needs to change to prevent your pristine newly cleansed system from slipping back into its current messy state? 
  • Do there need to be investments with how data is collected? 
  • Could some processes be better automated or systematised? 
  • Do you need some standard agreed & documented policies for how data is entered, a data dictionary etc.? 
  • Do you need to have a regular spring data clean to address the problems before they build up?

In terms of choosing a consultant, again I'd say involve some of your team in the process. In any eventuality they'll have to work closely together and they may also have key insights to differentiate between the snake-oil salesmen and the real experts. Also do your due diligence around how any potential consultant's is ensuring data security. For example ask how data will be transferred, when they'll dispose of it etc. But that's a question for another blog.

Wednesday, 13 November 2024

Replacing values in Power BI revisited


Back in 2022 I wrote a post detailing the various ways you can replace part of a string in M code (Power Query). It's actually the post I refer back to the most, but I've recently come across a couple of related posts so thought I would quickly add them here.

Replace values in a column using if statements

I adapted this one from this thread in the Fabric Forum. In the original example I was trying to remove the same string from any appearance of it in a field in a column, but what about if your problem is the other way around – i.e. the part you want to keep is always the same, but the part you want to lose varies, in unknowable ways.

In this case you can use an if function in the middle of the command like this:

= Table.ReplaceValue(#"Previous Step Name", each [Column1],each 

if Text.Start([Column1]), 7) = "My term" then "My new term" else [Column1],

Replacer.ReplaceValue,{"Column1"})

Replace/Swap multiple values for another value at once 

If you want to replace the entire contents of a cell with another value (by specifying the whole contents in both cases) then you can do use this:

= List.Accumulate({{"YYY", "yyyyy"}, {"XXX", "XXXXX"}},

        #"Expanded Table Column", (state, current) => Table.ReplaceValue(state, current{0},  current{1},  Replacer.ReplaceValue, {"Team"}))

Monday, 10 June 2024

Hacking PowerBI's Funnel Visual

This is a post I wrote specifically to support my entry to the Storytelling With Data's community monthly challenge for June, which is to create a funnel chart.

The real challenge of doing this in PowerBI is that native funnel diagram visual is terrible. Sure, if you have enough slices it just about looks kinda funnelly. But otherwise you just have a bar chart that’s centre aligned and rarely looks anything like a funnel at all (and is ugly to boot).

So I decided to figure out a way to manipulate the native tool into giving you what that manager/client wants, in a way that will dynamically re-adjust as fresh data comes in. That was the trickiest part of this challenge.

Essentially there are three key leaps that got me here: 
  1. Creating a calculated table in DAX to get the data in a format that the native funnel tool can use; where…
  2. you have sections consisting of many, very thin slices which allows you to get the slope shapes that you want by… 
  3. using maths to using make each slice decreasingly smaller between the values required. 
This could be done so you have one giant triangle shape, or if you only had three stages, (as in my case), so it forms the join between the main stages.

1. To make your calculated table you first have to conceptualize it at several smaller tables joined together, so for a 3-stage process you have a rectangular section (A) at the top, followed by a sloping section (B), another rectangular mid-section (C), a further sloping section (D) and finally the stem (E). For each additional stages you need to add 2 extra sections, a sloping section and the section itself.

2. To do this you go back to thinking about those 3 boring long thin lines. For sections A, C & E you're just going to take that length and divide it by a convenient number of slices (I used 25). So you now would have 25 shorter fatter lines of identical length. 

3. The trickiest bit is getting the slopes, but it's not that tricky because you know the length at the top and the bottom (from 2 above). Again you choose your number of slices (I used 15). All you need to do is to find the mid-point (the average length of your lines) and then, the length each will vary by to bridge the gap. If that sounds complex. Don't worry it's figured out below!

Two final points. I also used a measure to dictate the colour of the slice, hence why I have set up the ID column and done it in the way that I have. My colour measure just looks at the first digit and colour odd and even rows differently.

Secondly, even having done this, I was getting feint lines between each stage. To overcome this I just copied and pasted a second version of the diagram and aligned it on top of the original and slightly lower and the lines disappeared. I then grouped them.

The DAX below should work. But if you have any questions just drop me a comment.

Firstly my data looked like this:

For each date and each of the two campaign I'd get the number of calls who we couldn't contact, the number we contacted and who didn't renew and the number we contacted and they did review.

The DAX for the calculated table, then, looks like this:

Funnel Casual =

  1. VAR k = 25     // (Main sections - must be odd)
  2. VAR j = 15     // (Sloping sections must be odd)
  3.  
  4. VAR FilteredTable1 = Table
  5.  
  6. // SECTION A
  7. /////////////
  8. VAR TotalOutboundCalls = SUMX(FilteredTable1, 'Table'[Calls])
  9. VAR LengthValueCalls = TotalTableCalls / k
  10. VAR SectionA =
  11.     ADDCOLUMNS(
  12.         GENERATESERIES(401, 400 + k, 1),
  13.         "ID", [Value],
  14.         "Length", LengthValueCalls
  15.     )
  16.  
  17. //SECTION C
  18. ////////////
  19. VAR FilteredTable3 =
  20.     FILTER(
  21.         FilteredTable1,
  22.         'Table'[Contact] = "Yes"
  23.     )
  24. VAR TotalTableContacts = SUMX(FilteredTable3, 'Table'[Calls])
  25. VAR LengthValueContacts = TotalTableContacts / k
  26. VAR SectionC =
  27.     ADDCOLUMNS(
  28.         GENERATESERIES(201, 200 + k, 1),
  29.         "ID", [Value],
  30.         "Length", LengthValueContacts
  31.     )
  32.  
  33. //SECTION E
  34. ////////////
  35. VAR FilteredTable5 =
  36.     FILTER(
  37.         FilteredTable1,
  38.         'Table'[Renewal] = "Yes"
  39.     )
  40. VAR TotalTableRenewals = SUMX(FilteredTable5, 'Table'[Calls])
  41. VAR LengthValueRenewals = TotalTableRenewals / k
  42. VAR SectionE =
  43.     ADDCOLUMNS(
  44.         GENERATESERIES(1, k, 1),
  45.         "ID", [Value],
  46.         "Length", LengthValueRenewals
  47.     )
  48.  
  49. //SECTION B
  50. ////////////
  51. VAR LengthIncrementB = (LengthValueCalls - LengthValueContacts) / (j - 1)
  52. VAR SectionB =
  53.     ADDCOLUMNS(
  54.         GENERATESERIES(301, 300 + j, 1),
  55.         "ID", [Value],
  56.         "Length", IF([Value] = 301, LengthValueContacts, LengthValueContacts + (LengthIncrementB * ([Value] - 301)))
  57.     )
  58.  
  59. //SECTION D
  60. ////////////
  61. VAR LengthIncrementD = (LengthValueContacts - LengthValueRenewals) / (j - 1)
  62. VAR SectionD =
  63.     ADDCOLUMNS(
  64.         GENERATESERIES(101, 100 + j, 1),
  65.         "ID", [Value],
  66.         "Length", IF([Value] = 101, LengthValueRenewals, LengthValueRenewals + (LengthIncrementD * ([Value] - 101)))
  67.     )
  68.  
  69. RETURN
  70. UNION(SectionA, SectionB, SectionC, SectionD, SectionE)

If you have a more complicated table, or just one in a different format you can use line 4 to create / summarize / format / filter it as you wish first.

Thursday, 19 October 2023

Vlookups in Power Query (for power BI)

If you're familiar with Excel before moving to Power Query then it's a little maddening to find that PowerQuery doesn't have a built in "Vlookup" option. It's easily done via the M code though, you simply add this code:

Whole thing:
= Table.AddColumn(#"Previous Step", "Name of New Column", each #"Lookup Table"[LTTarget Field]{List.PositionOf(#"Lookup Table"[LTMatching Field], [Matching Field])},Text.Type)

Where the "Target Field" is the one you want to get the value from using the "Matching field" in the current table which corresponds to the "LTMatching Field" in the other table.

Add a Column Box
Alternatively you can just do this through the add a column box where you'd just put:

#"Lookup Table"[LTTarget Field]{List.PositionOf(#"Lookup Table"[LTMatching Field], [Matching Field])}


Usually though it's better just to merge the two queries. I do suspect this method might be a bit quicker though.

Wednesday, 2 August 2023

The new Twitter / 𝕏 logo as white png

↑ This is a temporary one and not designed to be viewed large as the lines are a bit wobbly. But I couldn't find a better one out there that was square rather than rectangular (and downloadable).
↓ Here is one with a border.
Hope these are useful.

Wednesday, 5 July 2023

Formula for converting US dates to UK in Excel

If you've ever imported data from a US supplier into a (UK) spreadsheet you may have found that the dates and times have gone wrong in Excel. This can happen in various ways but a difficult form of this problem sees the first twelve days of the month characterised back to front (i.e. days marked as month and vice versa) whereas those afterwards are just marked as weird text. IN this scenario the time is included and serves to complicate things further

There are various ways of solving this, although some only really work if you encounter this at the start of using the sheet, but none are particularly simple to implement.

One way – and this should work at any stage and if your dates are mixed up – is to use a formula. Here's one I've written using the ground-breaking new "Let" function which essentially lets you use variables. So if the first dodgy date is in A2 you type:

=LET(stringx,IFERROR(TEXT(ROUNDDOWN(A2,0),"dd/MM/yyyy"),TRIM(LEFT(A2,10))),

           firstslash, FIND("/",stringx),

           monthx, LEFT(stringx,firstslash-1),

           dayx, MID(stringx,firstslash+1,FIND("/",stringx,firstslash+1)-1-firstslash),

           yearx, RIGHT(stringx,4),

DATEVALUE(dayx &"-"& monthx &"-"& yearx))

What I've done here is create 5 variables. The first converts both types of date (pre and post 12th of month) into text and saves that as a string, stringx. The next finds the location of the one for the position of the first slash and then the last 3 use those two to create new strings/variables for day, month and year. Finally you plug those into a DATEVALUE function et voila

Thursday, 8 December 2022

Sum totals for Columns redux


Back October I showed how to run a quick sum of a column in Power Query. But I curious to know how I could see this total alongside a count of the number of rows. It turns out this is quite easy because you can include text in your output from a Power Query script. In fact you can even combine these two totals with an explanation as I have done above.

A few points to remember in doing this:
1. If you're creating a variable* in Power Query (i.e. a line in the M code) you don't have to call it right away you can call on it in the final "in" line.

2. You can't minx numbers with text unless you convert them to text first.

So the only code you need really (on top of what you many have already done) is:

#"Counted Rows" = Table.RowCount(#"PreviousRow"),
Total = List.Sum(#"Filtered Rows1"[Users])

in

"Total= "&Text.From(Total)&" from "&Text.From(#"Counted Rows")&" rows"


Friday, 28 October 2022

Add extra rows in Power Query dependent on value in cell/column

If you're working in Power Query, and you need to add a whole bunch of blank rows, or rows based on the value from another column. How do you do it?

I went round the houses with this one. There are two key pieces to the puzzle. The first is relatively easy/well known. If you split columns by delimiter you can (under advanced options) do this into new rows rather than new columns.

But how to get from the number in the cell/column to something with which split columns by delimiter could work?

At first I tried putting the cell (actually in my case it was a subtracting one cell from another) as a power of ten, but I couldn't work out how to get it out of 1e+48 mode, to then convert to text and delimit. 

Then I came across Catalin Bombea's post on this forum which I modified. If you add a new column using this formula:

= Table.AddColumn(Source, "NewColumnName", each Text.Repeat("¬",[ValueColumn]-1))

This will give you a string of ¬s as long as the value in the cell/column, for each row in the table (even if it's just 1. 

You then just use split by delimiter and away you go. Only tried it with Power BI but it should work with Excel too.

Thursday, 20 October 2022

How do you sum a total for a column in Power Query?


Power Query has a "Count Rows" button, but there's no equivalent button for when you want to quickly get the total of your values column, to see total sales or total users etc.

But there's good news! There are two relatively simple ways to do this. The one-step version for those happy to work in Advanced Editor, and the easier two-step version for those who aren't. Let's take them in reverse order.

The easier, two-step, version
1. Choose "Add Column">"Custom Column" and in the formula box just type "Total" (with quotes)
2. Now chose "Transform">"Group By". In the 1st box select your new column, under "Operation" choose "Sum" and under "Column" choose the column that has the values to be summed. Press OK to get the above! 

The one-step Advanced Editor version
In a way this is even simpler. Just go to Advanced Editor, put a column on the end of the last line of code and press "Enter". On the new line type Total = List.Sum(Source[Users]). Change the very last line from Source to Total and press OK.

Hat tip to John Dalesandro's post Microsoft Power Query for Excel Tips and Tricks, which gave me enough to work the rest out. Should work for Power Query in both Power BI and Excel.

Friday, 26 August 2022

Directives vs Commands in AHK/AutoHotKey

I couldn't find a direct answer to this question, so thought, once I'd managed to piece it together I'd post it here for any future searchers.

In general programming a command is a specific type of directive which tells a programme to do a particular task. However, AHK plays by its own rules. 

According to Frankie Bagnardi, in AHK "Directives are processed just before the script starts and allow you to customize AutoHotkey’s behaviour". There are two types. The first is just the bits of code at the top of a script, but they are also anything that starts with a #.

So in AHK directives are the bits of code starting with a # (hashtag/pound sign in the US)

So if you use, say, #IfWinActive partway down your code, the the commands that follow it will be specific to that context, until you turn it off (by using the same directive, with no conditions/parameters afterwards).

Directives are a type of commands which use a # to create a context. Bits of code that aren't functions, expressions, variables, parameters, text etc. are all commands, (e.g. Send, Sleep, Run, MsgBox). Directives are a specific subset of the available commands.

And, for the sake of completion, functions are those bits of code that come with brackets(parentheses). Expressions are bits of maths.

- If I've got this wrong, please let me know in the comments without shouting or calling me an idiot...

Saturday, 20 August 2022

iPad Native Keyboard Shortcuts


I've had an iPad for over a decade and always found it's keyboard, particularly the lack of backwards and forwards keys, frustrating. Recently however I got a new model and, quite by accident I discovered a useful shortcut that when I Googled, no-one else seems to have picked up on (or all the people who have are buried below the usual pile of SEO-d crap).

Anyway if you click the "I" key and then the "O" key in quick succession it selects the word the cursor is on or after. 

IO, just like like that!

In other words I-O (I+O?) is like double clicking with a mouse. It's a minor thing but gets me wondering what other hidden combos there are.

I set off trying to find out and then discovered that Apple have, in fact, done something closer to left and right arrow buttons. If you press and hold the space bar the markings blank out and you can then use the keyboard as a track pack. I got that thanks to this video by Steve Katz.

Does anyone know of any others?

Wednesday, 3 August 2022

How to get an editable list of all the files in a folder from Windows Explorer

Often you have a lot of files in a folder and for some reason you want to paste them in Word, Excel, Notepad or something else, but a straight select all, copy & paste doesn't work. While solutions exist for that online using the registry editor, they sound a bit foreboding or complicated, or your IT won't et you have permission. 

Here's an easier way: Copy the folder path from the bar in Windows Explorer (e.g. C:/Users/your.name/Documents) and drop it in to the URL bar in MS Edge or Chrome. Et voila! You can then copy and paste the text wherever you want.

If this doesn't work either check you've used "/"s and not "\"s. Secondly try using a different folder and navigating your way there through the folders in Chrome/Edge. 


Friday, 1 July 2022

How to Differentiate Between Similar Field Entries


Say you run a series of events and want to display registration, attendance etc on a bar chart in Power BI. The length of the event names and limitations on the Power BI naming fields in bar charts mean that you can't use the name on the Y-axis, and date gives you problems as well. So you go for a variation on the date worked out in a calculated field during the Power Query part of the process.

This is all fine until the day you run two events on the same day. Now Power BI thinks this is just one event. So you need to find someway of telling the difference between the two events, preferably with a reference to the date of the event.

A way to do this is to add a further calculated column using DAX. This will append an a & b (etc.)  onto the date field when there's a clash, but be blank otherwise. Here's the DAX to do that where 

St.Date =
VAR distinctlycounting = COUNTROWS(FILTER(Titles,Titles[Date]=EARLIER(Titles[Date])))
VAR ReIndex = CALCULATE(DISTINCTCOUNT(Titles[Title]),FILTER(Titles,
Titles[Date]=EARLIER(Titles[Date])&&
Titles[Title]<=EARLIER(Titles[Title])))

RETURN IF(distinctlycounting = 1,Titles[Start Date],SWITCH(ReIndex,
1, [Start Date] & "a",
2, [Start Date] & "b",
3, [Start Date] & "c",
4, [Start Date] & "d",
5, [Start Date] & "e",
6, [Start Date] & "f",
7, [Start Date] & "g",
8, [Start Date] & "h"
))

Where the table is called "Titles", the date field is called "Date" and "Start Date" is the calculated field in Power Query.

Obviously you can add more letter variations if you have more events in a single day, or do away with that bit altogether if you just want to use numbers (and you can also get rid of the CONVERT function wrap around as well.

Wednesday, 25 May 2022

Joining/Merging Columns in a single step


As per my previous post sometimes, for tidiness you just want to do something in a single step. So how do you do this with merging / joining / concatenating two columns into one in a single step in Power Query. Easy! (when you know how). Just paste this into your Advanced Editor:

 #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Previous Step Name", {{"Column2", type text}}, "en-GB"),{"Column1", "Column2"},Combiner.CombineTextByDelimiter("", QuoteStyle.None),"Column1"),
Where "Previous Step Name" is the name of the previous step, and "Column1" and "Column 2" are the imaginative titles for the two columns you want to merge. This will leave you with a single column called Column 1.

Remove/Replacing part of a string in Power Query


If you like keeping things neat and understandable in Power BI then you probably like to minimise things to one line. So there are times when, yeah, you could create a new IF column and then delete the original and rename it, but you're probably asking "how can I do this in one line of M code?"

Here's a solution for when you're trying to either remove a certain string(s) within a field, (as well as links to one that shows how to replace them).

Remove part of a string in a field
Say I have a field like this:

My Column
Which platforms do you use? Select all that apply
Tick those which work for you. Select all that apply
Which would you recommend? Select all that apply
Which are value for money? Select all that apply
Select all that apply

I want to get rid of all those uses of "Select all that apply". If I use the standard "replace" tool in Power Query it will blank the fifth line and leave the others untouched. I could create a new column here and then delete the original and rename the new one, but to do it in one move I can use this formula in the Advanced Editor:

#"Replaced Value" = Table.TransformColumns(#"Previous Step Name",{{"My Column", each List.Accumulate({{"Select all that apply","XX"}},_,(string,replace) => Text.Replace(string,replace{0},replace{1}))}})

Where "XX" is the term you are replacing it with (in this case just put "" i.e. blank).* 

It turns out you can also hit several replace terms in one columns at once by adding them into the second set of double curly brackets. So, if I want to replace xx with XX, yy with YY and zz with ZZ in Column1, I can do it like this

#"Replaced Value" = Table.TransformColumns(#"Previous Step Name",{{"Column1", each List.Accumulate({{"xx","XX"},{"yy","YY"},{"zz","ZZ"}},_,(string,replace) => Text.Replace(string,replace{0},replace{1}))}})

Alternatively if you want to hit multiple fields you can do that too.  So, if I want to replace xx with XX in column1, and bb with BB in Column2 I can write:

#"Replaced Value" = Table.TransformColumns(#"Previous Step Name",{
{"Column1", each List.Accumulate({{"xx","XX"}},_,(string,replace) => Text.Replace(string,replace{0},replace{1}))},
{"Column2", each List.Accumulate({{"bb","BB"}},_,(string,replace) => Text.Replace(string,replace{0},replace{1}))}
})

And obviously you can do both together if you wish.


*I found this info in the comments to the two videos included in this blog post by Guru G. The blog post itself covers two similar operations, 1. Removing multiple single characters from a field (video) & 2. Replacing a strings within a field with another string (video). 

Edit
Here's another simpler way from The Biccountant which is closer to the code you get if you use the standard tool.

= Table.ReplaceValue(#"Previous Step Name", each [Text to remove], "" ,Replacer.ReplaceText,{"Field to remove it from"})
Where the field containing the info you want to remove is called [Text to remove] and the field you are removing it from is called [Field to remove it from].

If you want to replace it with a specific value you just write a word or phrase in text in double quotes.
Alternatively, rather than a blank or text you can replace with the contents of another field, you just add this into the 3rd term like so:
= Table.ReplaceValue(#"Previous Step Name", each [Text to remove], each [Text to replace with], Replacer.ReplaceText,{"Field to remove it from"})
Where [Text to replace with] is the new field you want to replace with.



More of this? I added to the content from this post in a new post November 2024

Friday, 1 April 2022

Regex Differs Between Google Analytics and Google Search Console

If you're working with both Google Analytics and Google Search Console you've probably tried at some stage to get your head around regex. Regex is brilliant and is well worth investing time into getting to know. It's used by numerous platforms, but does vary a little from platform to platform.

However, Google takes things a step further. Regex is different on Google Analytics than it is in Google Search Console. 

This is particularly noticeable if you're trying to filter your search by URL and want to use markers to tie your needle to either the start or the end of the URL. Ordinarily you use a caret ^ to tie your search term to the start of the available text (or line), and a dollar sign $ to tie to the end. But Google complicates this.

So for Google Analytics if you want to find only those pages ending in your search term you use the $. If you want to make sure that this comes straight off the homepage you only need to include the caret - no need to refer to the stem. So if your domain is https://www.datageek.com using
^/news/$
Will find solely https://www.datageek.com/news/, no sub pages and not others like https://www.datageek.com/someothersection/news/

To do the same in Google Search Console though seems to want you to account for the variations in the stem, So to do the same as the above in Search Console you have to use
h.*datageek\.com/news/$
You would think Google would just choose one, but apparently not...