Show filtered information from MySql on a PowerBi graphic

27 Views Asked by At

I am relatively new to Power BI and currently working on creating a graphic that visualizes the registration year of cars based on their license plates.

For instance, I have license plates ranging from "AF-600-AA" to "AF-770-AA," this plates represent cars registered between October 2022 and January 2023.

I want to show a graphics bar with the cars of X registration year count

In SQL, I would achieve this using a query like:

SELECT * FROM vehicle WHERE plate BETWEEN "AD000AA" AND "AD400AA";

However, I am unsure how to apply a similar filter in Power BI to display this information in a bar chart. Can someone guide me on how to achieve this in Power BI?

Thank you!

1

There are 1 best solutions below

2
Sam Nseir On

You can do similar search between in PBI. Here is a DAX example via a Calculated Column:

Example = IF("AF-600-AA" <= [Plate] && [Plate] <= "AF-770-AA", "Yes", "No")

You could add a Calculated Column to your table with a SWITCH similar to:

Column = SWITCH(TRUE(),
  "AF-600-AA" <= [Plate] && [Plate] <= "AF-770-AA", "2022-Oct to 2023-Jan",
  "AF-800-AA" <= [Plate] && [Plate] <= "AF-970-AA", "2023-Feb to 2023-Apr"
  )

You may also want to do this in PowerQuery before the data loads into the dataset. Same concept applies.