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
xonder
Helper I
Helper I

TRUE FLASE between two dates

I collect data of advertised vehicles at irregulars intervals. Each time I collect data, I get a snapshot of what is currently being advertised along with a time stamp.

 

05.11.2020 is the first date of my data set and 08.11.2020 is the last date of my data set

 

ID05.11.202006.11.202007.11.202008.11.2020
1234561111
7890111110
1213140111
1516170110

 

I would like to  be able to answer the question "How many vehicles have been sold between dd.mm.yyyy and DD.MM.YYYY?"

 

A vehicle is sold if last date of a given ID is smaller than the last date of my data set.

 

If dd.mm.yyyy = 05.11.2020 and DD.MM.YYYY = 08.11.2020 then 2 vehicles, 789011 and 151617 have been sold.

 

If I change my page filter so that dd.mm.yyyy = 05.11.2020. and DD.MM.YYYY = 07.11.2020 then 0 vehicles have been sold.

 

How can I create a TRUE/FLASE measure that tells me wheather an ID has been sald and make sure that this measure changes depending on the date range selected.

 

here is by pbix file 

 

Thanks!

2 ACCEPTED SOLUTIONS
v-janeyg-msft
Community Support
Community Support

Hi, @xonder 

 

It’s my pleasure to answer for you.

According to your description,I think you can create a date slicer,then create a measure to calculate the desired rusult.

Like this:

 

Measure =
VAR a =
    SUMMARIZE (
        ALL ( azw ),
        [ID],
        "lastdata", MAX ( azw[date] ),
        "firstdata", MIN ( azw[date] )
    )
VAR selectedmin =
    CALCULATE ( MIN ( azw[date] ), ALLSELECTED ( azw ) )
VAR selectedmax =
    CALCULATE ( MAX ( azw[date] ), ALLSELECTED ( azw ) )
VAR b =
    ADDCOLUMNS (
        a,
        "status",
            IF (
                NOT ( [lastdata] < selectedmin
                    || [firstdata] > selectedmax ),
                IF ( [lastdata] < selectedmax, 1, 0 )
            )
    )
RETURN
    SUMX ( b, [status] )

 

1.png

Here is my sample .pbix file.Hope it helps.

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

Hi, @xonder 

 

Try to change 'all' to 'allselected' in the above formula.

 

Best Regards

Janey Guo

View solution in original post

5 REPLIES 5
v-janeyg-msft
Community Support
Community Support

Hi, @xonder 

 

It’s my pleasure to answer for you.

According to your description,I think you can create a date slicer,then create a measure to calculate the desired rusult.

Like this:

 

Measure =
VAR a =
    SUMMARIZE (
        ALL ( azw ),
        [ID],
        "lastdata", MAX ( azw[date] ),
        "firstdata", MIN ( azw[date] )
    )
VAR selectedmin =
    CALCULATE ( MIN ( azw[date] ), ALLSELECTED ( azw ) )
VAR selectedmax =
    CALCULATE ( MAX ( azw[date] ), ALLSELECTED ( azw ) )
VAR b =
    ADDCOLUMNS (
        a,
        "status",
            IF (
                NOT ( [lastdata] < selectedmin
                    || [firstdata] > selectedmax ),
                IF ( [lastdata] < selectedmax, 1, 0 )
            )
    )
RETURN
    SUMX ( b, [status] )

 

1.png

Here is my sample .pbix file.Hope it helps.

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

Hi @v-janeyg-msft ,

 

Is there a way to make the measure work with other filters than than azw[date]. All the charts on my work when filtered by azw[brand] except this one.

 

Here is an example of filtering by azw[brand] = "Mercedes". The number of cars sold (106) shoudl theoretically drop when this is selected to show the number of Mercedes' sold.

 

image.pngimage.png

Hi, @xonder 

 

Try to change 'all' to 'allselected' in the above formula.

 

Best Regards

Janey Guo

Hi @v-janeyg-msft ,

 

I get inconsitent results depending on the filter I use.

 

I created the measure as per you instructions:

 

Cars Sold = 
VAR a =
    SUMMARIZE (
        ALLSELECTED( azw ),
        [ID],
        "lastdata", MAX ( azw[date] ),
        "firstdata", MIN ( azw[date] )
    )
VAR selectedmin =
    CALCULATE ( MIN ( azw[date] ), ALLSELECTED ( azw ) )
VAR selectedmax =
    CALCULATE ( MAX ( azw[date] ), ALLSELECTED ( azw ) )
VAR b =
    ADDCOLUMNS (
        a,
        "status",
            IF (
                NOT ( [lastdata] < selectedmin
                    || [firstdata] > selectedmax ),
                IF ( [lastdata] < selectedmax, 1, 0 )
            )
    )
RETURN
    SUMX ( b, [status] )

 

 

And it works exactly as it should giving the correct result.

 

I then summarize this in a new table where I am able to qualify each ID at "Sold" or "For Sale":

 

 

Sale = 
VAR a =
    SUMMARIZE (
        ALLSELECTED( azw ),
        [ID],
        "lastdata", MAX ( azw[date] ),
        "firstdata", MIN ( azw[date] )
    )
VAR selectedmin =
    CALCULATE ( MIN ( azw[date] ), ALLSELECTED ( azw ) )
VAR selectedmax =
    CALCULATE ( MAX ( azw[date] ), ALLSELECTED ( azw ) )
VAR b =
    ADDCOLUMNS (
        a,
        "status",
            IF (
                NOT ( [lastdata] < selectedmin
                    || [firstdata] > selectedmax ),
                IF ( [lastdata] < selectedmax, "Sold", "For Sale" )
            )
    )
RETURN
    SUMMARIZE(b, azw[ID], [status], [lastdata], "selectedmax", CALCULATE(selectedmax))

 

 

And I get this table (hidden column title is "Cars Sold"):

 

image.png

Now I would like to use this table so this I can filter by sold/for sale. By deifintion, if I filter by sold, I should get keep the same total of 192. But for some reason this change to 186 as show below:

 

image.png

 

Do you have any explanation why the last 6 IDs are correctly marked as "Sold" but incorrection give value of 0?

 

Many thanks for your help.

amitchandak
Super User
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.