Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I'm pulling data from SQL for facility check-ins. I want only a list of people who are still in the building. In the attached screen shot, stationid 52 is a check-in station and stationid 192 is a check-out station. If memid has an entry for the stationid 192 check-out staion, I want to filter out both rows for stationid 52 and stationid 192, leaving only the rows for memid who have checked-in and no rows for memid who have checked-out. You can see in this screen shot that memid 98033 has a row for both stationid 52 and 192. I want both rows for memid 98033 filtered out.
Can you provide data that correlates to that? What my data returns is anyone that checked in, but didn't check out.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingHere's some data from today. The query, for it to work, can't pull from a static set of data. It needs to pull from our SQL database.
checkin | scancode | stationid | stationname |
5/30/2020 12:37 | 34477 | 187 | Ground Level Entry |
5/30/2020 12:37 | 29502 | 187 | Ground Level Entry |
5/30/2020 12:38 | 27185 | 187 | Ground Level Entry |
5/30/2020 12:39 | 27953 | 56 | Health & Wellness Check In |
5/30/2020 12:39 | 34166 | 56 | Health & Wellness Check In |
5/30/2020 12:39 | 27485 | 56 | Health & Wellness Check In |
5/30/2020 12:36 | 18650 | 52 | Main Check In |
5/30/2020 12:36 | 33553 | 52 | Main Check In |
5/30/2020 12:36 | 27953 | 52 | Main Check In |
5/30/2020 12:37 | 34166 | 52 | Main Check In |
5/30/2020 12:37 | 32226 | 52 | Main Check In |
5/30/2020 12:37 | 30959 | 52 | Main Check In |
5/30/2020 12:39 | 29502 | 192 | Member Check-Out |
5/30/2020 12:40 | 34477 | 192 | Member Check-Out |
5/30/2020 12:41 | 30959 | 192 | Member Check-Out |
The query I am giving you is sample code. I cannot pull from your SQL server. Did you use the steps in my query, but point it to your data source, not the static data? Giving me static data for today will still not pull from the SQL server.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingHi , @Anonymous
Could you please tell me whether your problem has been solved?
If it is, please mark the helpful replies or add your reply as Answered to close this thread.
It will help other community members easily find the solution when they get the similar issue.
Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Anonymous - here is the code that Power BI generates when you connect to a SQL server. This is connecting to a sales table in the AdventureWorks2017 database on my local machine:
let
Source = Sql.Database("localhost", "AdventureWorks2017"),
Sales_vIndividualCustomer = Source{[Schema="Sales",Item="vIndividualCustomer"]}[Data]
in
Sales_vIndividualCustomer
This is the sample code I provided to do what you requested:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZRLSwMxFIX/Sph1pXmcTBK3IiooLl3ULqoGKo4jTFvBf28y1RIVy72ZWWQ25577Sr7FojFzM9dSS+FOlW1mjTFKqvRX3qXzYnjb9U/iOr7HTpz32+GjWc5+BrVJppWyMv2tTsfN6rkXZ+v4+CKu+j9yn73b9NHkIZcEJQ1JrmXpno/LuOq2a3G/k1K34i52XR83m+MGh3zVBswZ6izWPjhL61Lti2w9TY5yQzU9jfdCK09cQk6hnJPE8trRHZbhbtB6TZO70r2m+WygnfeKli83bWwIgS7/3rwKoz6+PsRhH3Fyu9v+E4Lgajsq3xQx5xiijaN1ZWQ5s4oSR4NDvmqDtAbQClZfN5y2ZGMLzNAmCF+MhBgSiqtEC7GyeKlHQ1ADffCgDx70wYM+pkIfU6GPGuiDB33woI+p0AcP+uBBHzzogwd9TIU+eNAHD/rgQ/93CBv64EMfPOhjKvQxFfrgQR886IMPffChDz70wYL+8hM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"CHKINS checkin" = _t, #"MEMBERS scancode" = _t, #"STATIONS stationid" = _t, #"STATIONS stationname" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"CHKINS checkin", type datetime}, {"MEMBERS scancode", Int64.Type}, {"STATIONS stationid", Int64.Type}, {"STATIONS stationname", type text}}),
#"Added Date" = Table.AddColumn(#"Changed Type", "Date", each DateTime.Date([CHKINS checkin]), type date),
#"Grouped Rows" = Table.Group(#"Added Date", {"Date", "MEMBERS scancode"}, {{"All Rows", each _, type table [CHKINS checkin=datetime, MEMBERS scancode=number, STATIONS stationid=number, STATIONS stationname=text, Date=date]}}),
#"Added Checked Out Validation" =
Table.AddColumn(
#"Grouped Rows",
"Checked Out",
each (
List.ContainsAny([All Rows][STATIONS stationid], {187,52})
and List.Contains([All Rows][STATIONS stationid], 192)
)
, type logical),
#"Filtered out Checked Out IDs" = Table.SelectRows(#"Added Checked Out Validation", each ([Checked Out] = false)),
#"Expanded All Rows" = Table.ExpandTableColumn(#"Filtered out Checked Out IDs", "All Rows", {"CHKINS checkin", "STATIONS stationid", "STATIONS stationname"}, {"CHKINS checkin", "STATIONS stationid", "STATIONS stationname"}),
#"Removed Other Columns" = Table.SelectColumns(#"Expanded All Rows",{"CHKINS checkin", "MEMBERS scancode", "STATIONS stationid", "STATIONS stationname"})
in
#"Removed Other Columns"
You have to make the following changes to your M code after you've connected to the table in the SQL Server:
Unless you gave us all of the exact field names (and they have changed each time you did a copy of data from Excel), and by exact, I mean the exact number of characters, the case of the letters, etc., my code will fail, and you'll have to edit all of those in rows 5-17, and if you have other columns you need retained, then the expansion on row 16 needs to be edited. Additionally, the comparsons done on rows 7-14 assume your station is a whole number. If it is actually a text string with the numbers 192, 56, etc, then the comparsions will have to be redone as strings.
At this point, there is nothing more I can do to help via these forums. You have said you are a Power BI beginner, and I fully appreciate that. But you have asked for help in something that I would consider probably an intermediate process, so this isn't like helping with a complex Excel formula. To do anything more, we'd have to do a remote screen-share to fix, and that is now a consulting issue that I charge for, not free support in the forums to assist with tricky Power BI issues. You can PM me if you wish to pursue that, or you can find a Power BI consultant locally to come into your office to help getting it configured.
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingI keep getting "invalid HTML" errors on the headings when I try to paste the data into the table.
did you follow the directions in the links I provided, repeated below? The Table feasure can be finicky in the forum
How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingCovering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
96 | |
77 | |
66 | |
53 |
User | Count |
---|---|
144 | |
105 | |
102 | |
89 | |
63 |