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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
tmcateer4
Regular Visitor

Power BI query

This is my query... (the problem is I need to combine CUSTOMERACCOUNT numbers beginning in 90, 900 or 9 with it's matching account 880, 34 or 1178 but dropping the 90, 900 or 9. I tried using replace text but that didn't work.

let
Source = Sql.Database("hadbax1", "ProductionAX2012"),
dbo_HOS_SALEHST = Source{[Schema="dbo",Item="HOS_SALEHST"]}[Data],
#"Filtered Rows" = Table.SelectRows(dbo_HOS_SALEHST, each [INVOICEDATE] >= #datetime(2020, 1, 1, 0, 0, 0) and [INVOICEDATE] <= #datetime(2021, 12, 31, 0, 0, 0)),
#"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each ([ITEMCLASS] <> "2100" and [ITEMCLASS] <> "2101" and [ITEMCLASS] <> "2102" and [ITEMCLASS] <> "2103" and [ITEMCLASS] <> "2104" and [ITEMCLASS] <> "2106" and [ITEMCLASS] <> "2150" and [ITEMCLASS] <> "3920" and [ITEMCLASS] <> "9900" and [ITEMCLASS] <> "9999")),
#"Filtered Rows2" = Table.SelectRows(#"Filtered Rows1", each [INVOICEDATE] >= #datetime(2021, 1, 1, 0, 0, 0) and [INVOICEDATE] <= #datetime(2021, 12, 31, 0, 0, 0)),
#"Filtered Rows3" = Table.SelectRows(#"Filtered Rows2", each ([ITEMCLASS] <> "")),
#"Filtered Rows4" = Table.SelectRows(#"Filtered Rows3", each [INVOICEDATE] >= #datetime(2021, 1, 1, 0, 0, 0) and [INVOICEDATE] <= #datetime(2021, 12, 31, 0, 0, 0)),
#"Filtered Rows5" = Table.SelectRows(#"Filtered Rows4", each ([CUSTOMERCLASS] = "DS") and ([COMPANYNUM] = "01"))
in
#"Filtered Rows5"

5 REPLIES 5
Anonymous
Not applicable

Make sure that the CUSTOMERACCOUNT column is type text, then try typing this into the formula bar:

 

Table.TransformColumns(PriorStepName, {{"CUSTOMERACCOUNT", each Text.Range(_, 0, 2)}})

 

--Nate

Thank you for trying. But when I go to that column, it is filtered and shows

 = Table.SelectRows(#"Filtered Rows4", each ([CUSTOMERCLASS] = "DS") and ([COMPANYNUM] = "01"))

I did try adding it but nothing worked. Thanks.

Tracy

AlB
Community Champion
Community Champion

Hi @tmcateer4 

Do share some sample input data and the expected output for it. It will help clarify what you need.

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

This is an example of some of the data. The CUSTOMERACCOUNT includes a possible two or more account numbers such as 90034 or 34 and 90880 and 880. I want to drop the first three to 34 or first two numbers to 880 respectively whereas I can sum the net sales with the account numbers to one account number. How would I do that? Thanks so much!

 

tmcateer4_0-1624470276306.png

 

tmcateer4_1-1624470554946.png

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors