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
Anonymous
Not applicable

Clustered column chart and DAX query help

Hi experts,

Need help with clustered column chart and Dax formula

Not sure if I’m doing the right way

I have three tables

Period table, Date table, patient table

Period table has fields period date and sort columns

Sample data is like

Period

Date

Sort

Current Month To Date

Friday, 3 July 2020

3

Current Month To Date

Thursday, 2 July 2020

3

Current Month To Date

Wednesday, 1 July 2020

3

Current Week To Date

Friday, 3 July 2020

2

Current Week To Date

Thursday, 2 July 2020

2

Current Week To Date

Wednesday, 1 July 2020

2

Current Week To Date

Tuesday, 30 June 2020

2

Current Week To Date

Monday, 29 June 2020

2

Today

Friday, 3 July 2020

1

 

Date table contains all dates-example

date

year

month

Year/month

quarter

Year/quarter

dayofmonth

Saturday,4 july 2020

2020

07

2020/07

Q3

2020/q3

4

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

patient table contains

Admissionid

patientnumber

dateofbirth

name

admisiondate

dischargedate

nofodays

code

status

121166

101

01/01/1980

Kaz

Wednesday,10 june 2020

Fridayday,13june 2020

3

ABC

Coded

123617

101

01/01/1980

Kaz

friday,19june 2020

monday,22june 2020

4

CBE

Coded

124687

101

01/01/1980

kaz

Wednesday,1july 2020

Thursday,2july 2020

2

 

notcoded

121167

102

01/01/1981

Tod

Wednesday,10 june 2020

Fridayday,13june 2020

3

ABC

Coded

123618

102

01/01/1981

Tod

friday,19june 2020

monday,22june 2020

4

CBE

Coded

124688

104

01/01/1980

rez

Wednesday,1july 2020

Thursday,2july 2020

2

 

notcoded

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Relationships to table

Date to period – 1 to * (single)

Date to patient – 1 to *(single)

My requirement is to present in a chart

By slicer period table

 

Today,

Current week to date,

Current month to date,

Current year to date

 

could you please suggest or give a solution?

thanks in advance

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Patient:

c1.png

 

Date(a calculated table):

Date = CALENDAR(DATE(2020,1,1),DATE(2020,12,31))

 

Period:

c2.png

 

There is no realtionship between 'Period' and 'Patient'. You may create calculated columns and measures as below.

Calculated column:

Current Week To Date = 
IF(
    'Date'[Year]=YEAR(TODAY())&&'Date'[Weeknum]=WEEKNUM(TODAY())&&'Date'[Date]<=TODAY(),
    1,0
)

Current Month To Date = 
IF(
        'Date'[Year]=YEAR(TODAY())&&'Date'[Month]=MONTH(TODAY())&&'Date'[Date]<=TODAY(),
        1,0
)

Current Year to Date = 
IF(
            'Date'[Year]=YEAR(TODAY())&&'Date'[Date]<=TODAY(),
            1,0
)

 

Measure:

Visual Control = 
var _period = SELECTEDVALUE('Period'[Period])
var _tab =
ADDCOLUMNS(
    Patient,
    "min",
    SWITCH(
        _period,
        "Current Week to Date",MINX(FILTER(ALL('Date'),'Date'[Current Week To Date]=1),'Date'[Date]),
        "Current Month to Date",MINX(FILTER(ALL('Date'),'Date'[Current Month To Date]=1),'Date'[Date]),
        "Current Year to Date",MINX(FILTER(ALL('Date'),'Date'[Current Year to Date]=1),'Date'[Date]),
        BLANK()
    ),
    "max",
    SWITCH(
        _period,
        "Current Week to Date",MAXX(FILTER(ALL('Date'),'Date'[Current Week To Date]=1),'Date'[Date]),
        "Current Month to Date",MAXX(FILTER(ALL('Date'),'Date'[Current Month To Date]=1),'Date'[Date]),
        "Current Year to Date",MAXX(FILTER(ALL('Date'),'Date'[Current Year to Date]=1),'Date'[Date]),
        BLANK()
    )
)
var newtab=
ADDCOLUMNS(
    _tab,
    "flag",
    IF(
        NOT(
            OR(
                [admisiondate]>[max],
                [dischargedate]<[min]
            )
        ),
        1,0
    )
)
return
IF(
    ISFILTERED(Period[Period]),
    SUMX(
        newtab,
        [flag]
    ),
    1
)

 

Then you need to put the measure in the visual level filter and use 'Period' column from 'Period' table to filter out the result. Today is 7/6/2020.

c3.png

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @Anonymous 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Patient:

c1.png

 

Date(a calculated table):

Date = CALENDAR(DATE(2020,1,1),DATE(2020,12,31))

 

Period:

c2.png

 

There is no realtionship between 'Period' and 'Patient'. You may create calculated columns and measures as below.

Calculated column:

Current Week To Date = 
IF(
    'Date'[Year]=YEAR(TODAY())&&'Date'[Weeknum]=WEEKNUM(TODAY())&&'Date'[Date]<=TODAY(),
    1,0
)

Current Month To Date = 
IF(
        'Date'[Year]=YEAR(TODAY())&&'Date'[Month]=MONTH(TODAY())&&'Date'[Date]<=TODAY(),
        1,0
)

Current Year to Date = 
IF(
            'Date'[Year]=YEAR(TODAY())&&'Date'[Date]<=TODAY(),
            1,0
)

 

Measure:

Visual Control = 
var _period = SELECTEDVALUE('Period'[Period])
var _tab =
ADDCOLUMNS(
    Patient,
    "min",
    SWITCH(
        _period,
        "Current Week to Date",MINX(FILTER(ALL('Date'),'Date'[Current Week To Date]=1),'Date'[Date]),
        "Current Month to Date",MINX(FILTER(ALL('Date'),'Date'[Current Month To Date]=1),'Date'[Date]),
        "Current Year to Date",MINX(FILTER(ALL('Date'),'Date'[Current Year to Date]=1),'Date'[Date]),
        BLANK()
    ),
    "max",
    SWITCH(
        _period,
        "Current Week to Date",MAXX(FILTER(ALL('Date'),'Date'[Current Week To Date]=1),'Date'[Date]),
        "Current Month to Date",MAXX(FILTER(ALL('Date'),'Date'[Current Month To Date]=1),'Date'[Date]),
        "Current Year to Date",MAXX(FILTER(ALL('Date'),'Date'[Current Year to Date]=1),'Date'[Date]),
        BLANK()
    )
)
var newtab=
ADDCOLUMNS(
    _tab,
    "flag",
    IF(
        NOT(
            OR(
                [admisiondate]>[max],
                [dischargedate]<[min]
            )
        ),
        1,0
    )
)
return
IF(
    ISFILTERED(Period[Period]),
    SUMX(
        newtab,
        [flag]
    ),
    1
)

 

Then you need to put the measure in the visual level filter and use 'Period' column from 'Period' table to filter out the result. Today is 7/6/2020.

c3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

parry2k
Super User
Super User

@Anonymous make sure cross filter direction is set to both for the relationship between period table and date table, or in measures, make sure you are using CROSSFILTER DAX function and 3rd parameter value set to BOTH.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.