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

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.

Reply
sirpentagon
Frequent Visitor

Convert SQL Query to Dax measure

select

    InstanceId, count(DISTINCT Date)
from
    Storage
where
    month(date) = 12
    and year(date) = 2019
    and tags like '%DemoManaged%'
group by

    InstanceId

 

 

Hello, I am very new to Power BI and need help to create a new measure. The Main table (Storage) has around 25-30 columns.

The table contains InstanceId which I need to display in a Power BI - Table visualization along with the count.

I am able to do it through SQL query, and I am not able to create a new Measure for the same.

 

Any help is highly appreciated. 

2 ACCEPTED SOLUTIONS
JarroVGIT
Resident Rockstar
Resident Rockstar

Hi,
There is no need to create measures, you are asking for core functionality of PowerBI.
1. Create a table visual by clicking it in the Visuals pane.
2. Add Instance ID column by dragging it into the new table visual
3. Add Date column to visual by dragging it into the visual.
4. In the Visual pane, click on the little arrow downwards of Date entry and make sure it is not set to Date Hierarchy but to Date value. Then Reopen that menu and click count distinct.
Open the Filter pane and drag columns you want to filter to the Visual Filter area and apply the required filters.

Let me know of this answers your question and if it does please accept it as the solution.
Kind regards




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

v-lid-msft
Community Support
Community Support

Hi @sirpentagon ,

 

We can use the following measure after put the id into the table visual to meet your requirement:

 

Count =
CALCULATE (
    DISTINCTCOUNT ( 'Storage'[Date] ),
    FILTER (
        'Storage',
        'Storage'[Date] >= DATE ( 2019, 12, 1 )
            && 'Storage'[Date] <= DATE ( 2019, 12, 31 )
            && CONTAINSSTRING ( 'Storage'[tags], "DemoManaged" )
    )
)


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-lid-msft
Community Support
Community Support

Hi @sirpentagon ,

 

We can use the following measure after put the id into the table visual to meet your requirement:

 

Count =
CALCULATE (
    DISTINCTCOUNT ( 'Storage'[Date] ),
    FILTER (
        'Storage',
        'Storage'[Date] >= DATE ( 2019, 12, 1 )
            && 'Storage'[Date] <= DATE ( 2019, 12, 31 )
            && CONTAINSSTRING ( 'Storage'[tags], "DemoManaged" )
    )
)


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
JarroVGIT
Resident Rockstar
Resident Rockstar

Hi,
There is no need to create measures, you are asking for core functionality of PowerBI.
1. Create a table visual by clicking it in the Visuals pane.
2. Add Instance ID column by dragging it into the new table visual
3. Add Date column to visual by dragging it into the visual.
4. In the Visual pane, click on the little arrow downwards of Date entry and make sure it is not set to Date Hierarchy but to Date value. Then Reopen that menu and click count distinct.
Open the Filter pane and drag columns you want to filter to the Visual Filter area and apply the required filters.

Let me know of this answers your question and if it does please accept it as the solution.
Kind regards




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors