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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
anandfarmers
Advocate I
Advocate I

Notebook with sempy - giving a date range for filters

Hi All,

 

I have sempy working in Notebook and can pass filters as explained in Microsoft documentation.

filters = {
    "TestData[Prodct]": ["ABC1"]
    #,"State[State]": ["FLORIDA", "NEW YORK"]
}
df_measure = fabric.evaluate_measure(
    # Dataset name
    "FabricTraining-NewModelForUsers"
    # Measure
    ,"Sum of Price"
    # Group By
    ,["TestData[Prodct]"]
    # Filters
    ,filters=filters
)
df_measure
 
The above example work fine.
 
My question :
How can I pass a date range using this filters dictionary technique?
e.g. For Jan 2024 dates - do I need to list each date? 
That would make it dificult if the date range spans starting part of a month and ending part of another month.
 
Any  suggestions?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @anandfarmers ,

Apologies for the delay in reply from our side. 

fabric.evaluate_measure has the limitation of the filter that only suppors the 'in' operator.
If you are looking towards range operation then i recommed to use fabric.evaluate_dax .

For eg:

import sempy.fabric as fabric

df_dax = fabric.evaluate_dax(
    "Customer Profitability Sample",
    """
    EVALUATE SUMMARIZECOLUMNS(
        'State'[Region],
        'Calendar'[Year],
        'Calendar'[Month],
        'State'[State],
        FILTER('Calendar', 'Calendar'[Year] >= 2009 && 'Calendar'[Year] <= 2011),
        )
    """)

df_dax


Inorder to get some idea please refer below link,
Read data from semantic models and write data that semantic models can consume - Microsoft Fabric | ...
FILTER function (DAX) - DAX | Microsoft Learn

Hope this is helpful. Please let me know incase of further queries.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @anandfarmers ,

Thanks for using Fabric Community.
Can you please check if below code works for you, it can get data filter by month and year.

 

 

import sempy.fabric as fabric

filters = {
    "State[Region]": ["East", "Central"],
    "State[State]": ["FLORIDA", "NEW YORK"],
    "Calendar[Month]": ["Aug"],
    "Calendar[Year]": [2013]
}

df_measure = fabric.evaluate_measure(
    "Customer Profitability Sample",
    "Total Revenue",
    ["Customer[State]", "Calendar[Date]", "Calendar[Month]", "Calendar[Year]"],
    filters=filters)

df_measure

 

 

 

vgchennamsft_0-1704797322361.png

Hope this is helpful. Please let me know incase of further queries.

Hi @Anonymous ,

Thanks for the reply.

I understand we can give month name.

But as I mentioned, if the date range starts part of a month and ends part of the same month or another  month then we have to list each date. e.g. 2nd of Jan 2023 to 5th of March 2023.

 

I am trying to understand how to give such date ranges.

Anonymous
Not applicable

Hi @anandfarmers ,

Apologies for the delay in reply from our side. 

fabric.evaluate_measure has the limitation of the filter that only suppors the 'in' operator.
If you are looking towards range operation then i recommed to use fabric.evaluate_dax .

For eg:

import sempy.fabric as fabric

df_dax = fabric.evaluate_dax(
    "Customer Profitability Sample",
    """
    EVALUATE SUMMARIZECOLUMNS(
        'State'[Region],
        'Calendar'[Year],
        'Calendar'[Month],
        'State'[State],
        FILTER('Calendar', 'Calendar'[Year] >= 2009 && 'Calendar'[Year] <= 2011),
        )
    """)

df_dax


Inorder to get some idea please refer below link,
Read data from semantic models and write data that semantic models can consume - Microsoft Fabric | ...
FILTER function (DAX) - DAX | Microsoft Learn

Hope this is helpful. Please let me know incase of further queries.

Thank you for the reply.

It calrifies different use cases of the functions.

Anonymous
Not applicable

Hi @anandfarmers ,

Glad to know that your query got resolved. Please continue using Fabric Community for your further queries.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors