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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Bakhtawar
Post Patron
Post Patron

values on the bases of selecting dates

For suppose

my date range is 1st feb to 28th feb
I can select date filter like 5th feb to 28th feb then I need count of 1st feb to 5th feb in the results. How could I get through dax.

 

I used only one date and drag in slicer .. and there is two columns in table .. date and values

 
1 ACCEPTED SOLUTION

Hi, @Bakhtawar 

 

Based on the description, I created my data to reproduce your scenario.

Table:

a1.png

 

You may create a measure as follows.

 

Count = 
var _mindate = 
CALCULATE(
    MIN('Table'[Date]),
    ALL('Table')
)
var _maxdate = 
CALCULATE(
    MIN('Table'[Date]),
    FILTERS('Table'[Date])
)
var _result = 
COUNTROWS(
    FILTER(
        ALL('Table'),
        'Table'[Date]>=DATE(YEAR(_mindate),MONTH(_mindate),1)&&
        'Table'[Date]<_maxdate
    )
)
return 
IF(
    ISBLANK(_result),
    0,
    _result
)

 

 

Result:

a2.png

 

a3.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

13 REPLIES 13
v-alq-msft
Community Support
Community Support

Hi, @Bakhtawar 

 

I think I misunderstand your thought. I wonder if you want to sum the value for unselected dates. Here is my sample.

Table:

f1.png

 

You may create a measure as follows.

 

NotSelectedCount = 
CALCULATE(
    SUM('Table'[Value]),
    FILTER(
        ALL('Table'),
        NOT( 'Table'[Date]) in FILTERS('Table'[Date])
    )
) 

 

 

Result:

f3.png

 

f2.png

If I misunderstand your thoughts, please show me your sample data and expected result. Do mask sensitive data before uploading. Thanks

 

Best Regards

Allan

 

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

 

@v-alq-msft @Ashish_Mathur 

 

i have data like this

Datevalues
10/18/201924
10/23/201925
10/23/201926
11/13/201927
11/13/201928

 

there is zig zag dates..

so when i drag this date column in slicer

 

suppose if i select date from 10/23/2019 to 11/13/2019 then output should be 1 beacuse from begining of month of october

10/1/2019 to 10/23/2019 only 10/18/2019 is inculueded in data .. so output should be 1

 

and if you select date 11/13/2019 then output should be be 3 beacuse from the this date 11/13/2019 only 3 previous dates are avaible

Hi, @Bakhtawar 

 

Based on the description, I created my data to reproduce your scenario.

Table:

a1.png

 

You may create a measure as follows.

 

Count = 
var _mindate = 
CALCULATE(
    MIN('Table'[Date]),
    ALL('Table')
)
var _maxdate = 
CALCULATE(
    MIN('Table'[Date]),
    FILTERS('Table'[Date])
)
var _result = 
COUNTROWS(
    FILTER(
        ALL('Table'),
        'Table'[Date]>=DATE(YEAR(_mindate),MONTH(_mindate),1)&&
        'Table'[Date]<_maxdate
    )
)
return 
IF(
    ISBLANK(_result),
    0,
    _result
)

 

 

Result:

a2.png

 

a3.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.

@v-alq-msft  this help me out thanks

 

but i have another field account number .. when i select dates and did not select account number then worked fine

 

but when i select dates and select account number then expected output is wrong

 

wheree as that account number field is in the same table.. so where i pass account number ?

Hi, @Bakhtawar 

 

Please show us your sample data and expected result. Do mask sensitive data before uploading.

 

Best Regards

Allan

@v-alq-msft  probelm solved thanks

Hi,

Setup the PBI file like i have mentioned in my previous post.  Write this measure

Count of rows from beg of month to first date of selected date range = CALCULATE(COUNTROWS(Data),DATESBETWEEN(Calendar[Date],EOMONTH(MIN(Calendar[Date]),-1)+1,MIN(Calendar[Date])-1))

If the date selected in the slicer is 11/13/2019, then the result should be 0 because there is no entry from 11/1/2019 to 11/12/2019.


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

Hi,

Create a Calendar Table.  Build a relationship from the Date columm of the Data Table to the Date column of the Calendar Table.  Build a slicer from the Date column of the Calendar Table and write this measure

Values = SUM(Data[Value])

Values from beg of month to first date of selected date range = CALCULATE([Values],DATESBETWEEN(Calendar[Date],EOMONTH(MIN(Calendar[Date]),-1)+1,MIN(Calendar[Date])))

Hope this helps.


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

@Bakhtawar 

Make sure you have date calendar and try like

Measure =
var _max = minx(Date,Date[Date])
var _min= date(year(_max),month(_max),1)
return
calculate(count(table[Value],filter(all(Date),Date[Date]<= _max && Date[Date]>= _min))

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

Appreciate your Kudos

Ashish_Mathur
Super User
Super User

Hi,

What result would you expect if you select the date range as 10 Feb to 20 Mar?


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


@Ashish_Mathur wrote:

Hi,

What result would you expect if you select the date range as 10 Feb to 20 Mar?


@Ashish_Mathur  count from 1 to 10 feb

v-alq-msft
Community Support
Community Support

Hi, @Bakhtawar 

 

Based on your description, I created data to reproduce your scenario.

Table:

b1.png

 

Then you may create two measures. One is for count of selected values and another is for count of  not selected values.

 

SelectedCount = 
CALCULATE(
    DISTINCTCOUNT('Table'[Date]),
    FILTERS('Table'[Date])
)

NotSelectedCount = 
CALCULATE(
    DISTINCTCOUNT('Table'[Date]),
    FILTER(
        ALL('Table'),
        NOT( 'Table'[Date]) in FILTERS('Table'[Date])
    )
) 

 

 

Result:

b2.png

b3.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.

Saurabh8437
Frequent Visitor

So you want sum of values in time period excluding selected period?

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.