Forum Discussion

anandfarmers's avatar
anandfarmers
Icon for Advocate I rankAdvocate I
2 years ago
Solved

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?

5 Replies

  • Anonymous's avatar
    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

     

     

     

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

    • anandfarmers's avatar
      anandfarmers
      Icon for Advocate I rankAdvocate I

      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.