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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
rkgundabhat
Helper I
Helper I

Filter data

Hello , 

My table has these columns CaseNumber ,Department, CaseOpenedDate, CaseTerminatedDate, CaseCloseDate. I want to know cases which were open in a given month. My example query for the cases which were open on Sep 2022 would be

Select * from Table where CaseOpenedDate <= '30-Sep-2022' and CaseTerminatedDate is null or CaseTerminatedDate >= '01-sep-2022' and CaseCloseDate is null or CaseCloseDate >= '01-sep-2022' 

In my dashboard I want to be able to select Date filter and Department and get all the cases where were open in any month. 

Need help with this please. 

 

Thank you

RK

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@rkgundabhat 

Please try this measure:

Open Cases = 
CALCULATE(
    COUNTROWS('CaseTable'),
    FILTER(
        'CaseTable',
        'CaseTable'[CaseOpenedDate] <= MAX('Dates'[Date]) &&
        (
            'CaseTable'[CaseTerminatedDate] = BLANK() ||
            'CaseTable'[CaseTerminatedDate] >= MIN('Dates'[Date])
        ) &&
        (
            'CaseTable'[CaseCloseDate] = BLANK() ||
            'CaseTable'[CaseCloseDate] >= MIN('Dates'[Date])
        )
    )
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

Share some data to work with (in a format that can be pasted in an MS Excel file) and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

CaseNumberDepartmentCaseOpenedDateCaseTerminatedDateCaseCloseDate
1231HR6/2/20216/2/20226/3/2022
1232Accounts9/15/20226/2/202310/2/2023
1233Facility2/23/2023 6/2/2023
1234IT2/1/201910/2/202211/2/2022

The request is "Show all the cases active in a given month for a department" . 

I figured that I need to use the above query to get my the result which would be cases 1232 and 1234. 

In my report canvas I have filter for department so if I select IT then my count should be 1. 

I am not able to understand what filter do I need to select a year/month in the canvas to get the count for a  department and how to use the query. 

Fowmy
Super User
Super User

@rkgundabhat 

Please try this measure:

Open Cases = 
CALCULATE(
    COUNTROWS('CaseTable'),
    FILTER(
        'CaseTable',
        'CaseTable'[CaseOpenedDate] <= MAX('Dates'[Date]) &&
        (
            'CaseTable'[CaseTerminatedDate] = BLANK() ||
            'CaseTable'[CaseTerminatedDate] >= MIN('Dates'[Date])
        ) &&
        (
            'CaseTable'[CaseCloseDate] = BLANK() ||
            'CaseTable'[CaseCloseDate] >= MIN('Dates'[Date])
        )
    )
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

This is working as I wanted. So I created a meansure as you suggested and created dates table from below.  I added this OpenCases measure to my Cases table and used the Dates table as filter. 

Thank you so much Fowmy

I think from the above DAX code , I only have CaseTable. What is the Dates table and the Date column?

Working on it

I am getting an error cannot find the name "Dateserror.png"

@rkgundabhat 

Create a Dates table with the code that I have given below but no need for a relationship to be made, use the Year Month on a Slicer to select the month:

Dates = 
ADDCOLUMNS(
    CALENDAR("01/01/2019","31/12/2023"),
    "Month No" , MONTH([Date]),
    "Month Name", FORMAT([Date],"Mmmm"),
    "Year",YEAR([Date]),
    "Year Month No", INT(FORMAT([Date],"yyyymm")),
    "Year Month" , FORMAT([Date],"Mmm yyyy"),
    "Quarter No", QUARTER([Date]),
    "Quarter" , FORMAT([Date],"\QQ")
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

I am getting output without errors. I will QA the data and get back to you . Please bear with me. 

Thank you so much

Helpful resources

Announcements
FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.