Akshay Waghavakar on LinkedIn: ๐Ÿ“Š Analytics Tip: Calculating Last Year Sales in Power BI using DAXโ€ฆ (2024)

Akshay Waghavakar

Power BI | SQL | Excel | Data Warehouse | Python learner

  • Report this post

๐Ÿ“Š Analytics Tip: Calculating Last Year Sales in Power BI using DAX ๐Ÿš€Quickly retrieve last year's sales data for your Power BI reports.Here's a handy Data Analysis Expressions (DAX) formula using the #SAMEPERIODLASTYEAR function:DAX:LY SalesAmount = CALCULATE([Sales], SAMEPERIODLASTYEAR(DimTime[Date].[Date]))This formula calculates the SalesAmount for the same period last year. Simply replace [Sales] and DimTime[Date].[Date] with your actual sales measure and date column.----------------------------------------------------------------#SAMEPERIODLASTYEAR()Returns a table that contains a column of dates shifted one year back in time from the dates in the specified dates column, in the current context.Syntax:SAMEPERIODLASTYEAR(<dates>)Stay empowered with your Power BI analytics! ๐Ÿ’ผ๐Ÿ“ˆ #PowerBI #DAX #DataAnalytics #BusinessIntelligence #powerbideveloper #functions #interview

  • Akshay Waghavakar on LinkedIn: ๐Ÿ“Š Analytics Tip: Calculating Last Year Sales in Power BI using DAXโ€ฆ (2)

9

Like Comment

To view or add a comment, sign in

More Relevant Posts

  • Krishna Sameera Kota

    Aspiring Data Analyst | Expert in Advanced Excel, SQL & Power BI | Transforming Data into Strategic Insights

    • Report this post

    Power BI Scenario-Based Questions: #Day2Hello Everyone!!!๐Ÿค” You have a table named Sales with columns Sales Amount, Product Category, and Sale Date. Compare the total sales for each product category against the previous yearโ€™s sales.๐Ÿ’ก Approach-1:Sales Comparison =VAR CurrentYearSales = SUM(Sales[Sales Amount])VAR PreviousYearSales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR(Sales[Sale Date]))RETURNCurrentYearSales - PreviousYearSales๐Ÿ’ก Approach-2:Sales Comparison =VAR CurrentYearSales = SUM(Sales[Sales Amount])VAR PreviousYearSales = CALCULATE(SUM(Sales[Sales Amount]),PARALLELPERIOD(Sales[Sale Date], -1, YEAR))RETURNCurrentYearSales - PreviousYearSales๐Ÿ”‘ Key Points:* VAR keyword is used to define variables within a DAX expression.Syntax: VAR <VariableName> = <Expression>RETURN <ResultExpression>* SAMEPERIODLASTYEAR calculates a value for the same period in the previous yearSyntax: SAMEPERIODLASTYEAR(<dates>)* PARALLELPERIOD shifts the date context by a specified number of periods, which can be useful for comparing sales over different periods.Syntax: PARALLELPERIOD(<dates>, <number_of_periods>, <period>)..#Day1 - https://lnkd.in/dnk_uwNaFeel free to share your answers and insights in the comments.Follow Krishna Sameera Kota for regular updates on Data Analytics.Thank you! Have a nice day!...Codebasics Dhaval Patel Hemanand Vadivel Shakra Shamim Shashank Singh ๐Ÿ‡ฎ๐Ÿ‡ณ Munna Das Thodupunuri Bharath MADHU THANGELLA Raghavan PVenkata Naga Sai Kumar Bysani Shail Sahu Karthimeena Rangarajan Priyanka SG Arun R. AMAN KUMAR #PowerBI #PowerBIQuestions #DAX #scenarios #PracticeMakesPerfect #InterviewPrep #learntogether #careerdevelopment #dataanalytics #interviewquestions #practice #consistencymatters

    122

    13 Comments

    Like Comment

    To view or add a comment, sign in

  • Taibat Abowaba

    Data analytics โ€ข Data science โ€ข Microsoft Excel โ€ข SQL โ€ข Power BI โ€ข Python โ€ข Machine learning โ€ข Power point

    When to Use Basic Aggregate functions and their X variants in Power BI (DAX)As a beginner, you might find it tricky to know when and how to use basic aggregate functions like AVERAGE and their X variants such as AVERAGEX in Power BI. Understanding their appropriate use can significantly impact the accuracy of your analysis. Let me guide you through it๐Ÿ˜AVERAGE: This function is straightforward. It calculates the average of an entire column in a table.Example: Imagine you have a sales table with amount and quantity columns. Using AVERAGE on the amount column would give you the average of all sales amounts. Formula: Average_amount = AVERAGE(Sales[Amount])AVERAGEX: This function is more flexible and powerful. It iterates over a table (or a table expression) and evaluates an expression for each row, then returns the average of those evaluated values.Example: Suppose you have a sales table with product category and amount columns, and you need to calculate the average amount based on categories. This is where AVERAGEX shines. Itโ€™s perfect for scenarios where the value to average involves more complex expressions rather than a simple column reference.Formula: Average_amount_per_category = AVERAGEX(VALUES(Sales[Category]), [TotalSales])Other Basic Aggregate Functions and Their X Variants:SUM vs. SUMX, COUNT vs. COUNTX, COUNTA vs. COUNTAx, MIN vs. MINX, MAX vs. MAXX, MEDIAN vs. MEDIANX, STDEV vs. STDEVX, VAR vs. VARX. Just like AVERAGE VS AVERAGEX, these functions have similarities in their formulas and usage.I hope you found this helpful. #dataanalysis #dataanalytics #datascience #dax #machinelearning

    5

    Like Comment

    To view or add a comment, sign in

  • Harleen Kaur

    Data Analyst | MSc data science | Salesforce Certified Data Cloud Consultant | 5โญ๏ธHacker rank @ SQL| Python| Excel | Tableau | Power BI | Machine Learning | Statistics

    • Report this post

    Understanding AVERAGE vs. AVERAGEA in Power BIEver wondered why your average calculations in Power BI donโ€™t always match up? Let's break down the key differences between AVERAGE and AVERAGEA:๐Ÿงฎ AVERAGE FunctionWhat it does: Calculates the mean of numeric values in a column.Ignores: Text, logical values (TRUE/FALSE), and blanks.Example:= AVERAGE(InternetSales[ExtendedSalesAmount]) ๐Ÿ“Š AVERAGEA FunctionWhat it does: Calculates the mean, including numbers, text, and logical values.Handles non-numeric data:Values that evaluate to TRUE count as 1.Values that evaluate to FALSE count as 0.Non-numeric text counts as 0.Empty text ("") counts as 0.Example:= AVERAGEA([Amount]) Example:Imagine you have the following data:Transaction 1: Amount = 1Transaction 2: Amount = 20Transaction 3: Amount = n/a (non-numeric text)Transaction 4: Amount = (blank)Transaction 5: Amount = TRUEResults:AVERAGE of Amount: (1+20)/2=10.5(1+20)/2=10.5AVERAGEA of Amount: (1+20+0+0+1)/5=4.4(1+20+0+0+1)/5=4.4Quick Tip:Use AVERAGE: For pure numeric columns.Use AVERAGEA: When your column has a mix of numbers, logical values, and text.Next time you need to calculate averages, make sure to pick the right function for accurate results! ๐Ÿ’ก#PowerBI #DataAnalytics #BusinessIntelligence #DataScience #PowerTips

    3

    Like Comment

    To view or add a comment, sign in

  • RAHUL VALLURI

    Enthusiastic Data Analyst || Proficient in Excel, Power BI, and SQL ||Transforming Data into Strategic Insights || Passionate About Data Storytelling

    • Report this post

    ๐Ÿ’ก๐‚๐š๐ฅ๐œ๐ฎ๐ฅ๐š๐ญ๐ž๐ ๐‚๐จ๐ฅ๐ฎ๐ฆ๐ง ๐ฏ๐ฌ. ๐‚๐š๐ฅ๐œ๐ฎ๐ฅ๐š๐ญ๐ž๐ ๐Œ๐ž๐š๐ฌ๐ฎ๐ซ๐ž: ๐–๐ก๐ž๐ง ๐ญ๐จ ๐”๐ฌ๐ž ๐„๐š๐œ๐ก?Ever wondered whether to go with a calculated column or a calculated measure in Power BI? Here's a simple way to decide! ๐Ÿ‘‡๐Ÿ”น ๐‚๐š๐ฅ๐œ๐ฎ๐ฅ๐š๐ญ๐ž๐ ๐‚๐จ๐ฅ๐ฎ๐ฆ๐ง:โœ… Use when you need to create new data thatโ€™s stored in the table for every row.โœ… Works well when filtering or slicing the data by specific attributes.๐Ÿ”น ๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž:Imagine you have a sales table and want to create a Profit Margin column for each product.๐Ÿ”„ Formula: (Sales - Cost) / SalesThis is a calculated column because itโ€™s a value you want available for every single row in your table.๐Ÿ”น ๐‚๐š๐ฅ๐œ๐ฎ๐ฅ๐š๐ญ๐ž๐ ๐Œ๐ž๐š๐ฌ๐ฎ๐ซ๐ž:โœ… Use when you want to perform calculations based on user interactions (like slicing, filtering, or aggregating data).โœ… Measures only calculate when theyโ€™re used in visuals.๐Ÿ”น๐„๐ฑ๐š๐ฆ๐ฉ๐ฅ๐ž:Say you want to calculate Total Profit Margin across all products based on the current filters applied in your report.๐Ÿ”„ Formula: SUM(Sales) - SUM(Cost) / SUM(Sales)This is a calculated measure because itโ€™s a dynamic result that changes based on filters and slicers in your report.๐Ÿ”‘ ๐Š๐ž๐ฒ ๐ƒ๐ข๐Ÿ๐Ÿ๐ž๐ซ๐ž๐ง๐œ๐ž:- Calculated columns are pre-calculated and stored in the data model for each row.- Measures are calculated on the fly, based on the current context.Hope this helps! ๐Ÿ˜Š Have you faced any interesting challenges with calculated columns or measures in your Power BI projects? I'd love to hear your thoughts!#PowerBI #DataAnalysis #CalculatedColumns #CalculatedMeasures #DAX #DataAnalytics #PowerBItips

    13

    Like Comment

    To view or add a comment, sign in

  • Power BI | SQL | Excel | Data Warehouse | Python learner

    • Report this post

    The DATEADD function in DAX (Data Analysis Expressions) in Power BI is used to add or subtract a specified number of intervals (such as days, months, quarters, or years) to a given date and return the resulting date.Here's the syntax of the DATEADD function:DATEADD(<start_date_column>, <number_of_intervals>, <interval>)- `<start_date_column>: This is the column containing the starting date to which you want to add intervals.- <number_of_intervals>: This is the number of intervals (e.g., days, months, years) to add or subtract. It can be positive to add intervals or negative to subtract intervals.- <interval>: This specifies the type of interval to add or subtract. It can be "day", "month", "quarter", or "year".Here's an example of how to use the DATEADD function in Power BI DAX:Suppose you have a Sales table with a column named "OrderDate" containing the date of each order. You want to create a new calculated column that adds 7 days to each order date.NewOrderDate = DATEADD(Sales[OrderDate], 7, DAY)This will create a new column named "NewOrderDate" in your Sales table, where each date is increased by 7 days.Similarly, you can subtract intervals by providing a negative number in the `<number_of_intervals>` parameter. For example, to subtract 1 month from the "OrderDate" column:NewOrderDate = DATEADD(Sales[OrderDate], -1, MONTH)This will create a new column where each date is reduced by 1 month.Keep in mind that the DATEADD function respects the calendar hierarchy in Power BI, so if your data is structured with a calendar hierarchy, the function will adjust dates accordingly within that hierarchy (e.g., considering leap years, end of month adjustments, etc.).#dax #functions #powerbideveloper #analysis

    1

    1 Comment

    Like Comment

    To view or add a comment, sign in

  • Krishna Sameera Kota

    Aspiring Data Analyst | Expert in Advanced Excel, SQL & Power BI | Transforming Data into Strategic Insights

    • Report this post

    Power BI Scenario-Based Questions: Daily Insights #Day1Hello Everyone!!!I'm starting a new series to share scenario-based questions to challenge and enhance our Power BI skills.I hope these questions aid in your preparation. Feel free to share your answers and insights in the comments.๐Ÿค” You have a sales table with columns for Order Date, Sales Amount, and Region. Create a measure that calculates the average sales amount for the last 3 months. ๐Ÿ’ก Approach-1:Average Sales Last 3 Months =CALCULATE(AVERAGE(Sales[Sales Amount]),DATESINPERIOD(Sales[Order Date], MAX(Sales[Order Date]), -3, MONTH))๐Ÿ’ก Approach-2:Average Sales Last 3 Months =AVERAGEX(DATESINPERIOD(Sales[Order Date], MAX(Sales[Order Date]), -3, MONTH),[Sales Amount])๐Ÿ”‘ Key Points:* DATESINPERIOD returns a table containing a set of dates that begin with a specified start date and continue for a specified number of intervals.Syntax: DATESINPERIOD(<dates>, <start_date>, <number_of_intervals>, <interval>)In this case, it returns a table of dates within the last 3 months from the most recent date in the Order Date column. * CALCULATE function is used to modify the filter context and perform the calculation based on the specified conditions.Syntax: CALCULATE(<expression>, <filter1>, <filter2>, ...)*AVERAGEX function allows you to perform row-wise calculations and then take the average of those results.Syntax: AVERAGEX(<table>, <expression>)..Follow Krishna Sameera Kota for regular updates on Data Analytics.Thank you! Have a nice day!...Codebasics Dhaval Patel Hemanand Vadivel Shakra Shamim Shashank Singh ๐Ÿ‡ฎ๐Ÿ‡ณ Munna Das Thodupunuri Bharath MADHU THANGELLA Raghavan P Venkata Naga Sai Kumar Bysani Shail Sahu Karthimeena Rangarajan Priyanka SG Arun R. AMAN KUMAR #PowerBI #PowerBIQuestions #DAX #scenarios #PracticeMakesPerfect #InterviewPrep #learntogether #careerdevelopment #dataanalytics #interviewquestions #interviewpreparation #practice #consistencymatters

    98

    4 Comments

    Like Comment

    To view or add a comment, sign in

  • Pruthvi Gohil

    Software Engineer at Magnusminds IT Solutions

    • Report this post

    ๐ŸŒŸ Excited to share some insights on Power BI! Check out my latest blog post on YTD (Year-to-Date) and YoY (Year-over-Year) calculations. Learn how to leverage these powerful features in your analytics journey: https://lnkd.in/drSsiWgf#PowerBI #DataAnalytics #YearToDate #YearOverYear #businessintelligence #dax #daxfunctions MagnusMinds IT Solution

    24

    Like Comment

    To view or add a comment, sign in

  • Tarun Gupta

    Business Intelligence Analyst @ Atlas Copco | Master of Science, Bachelor of Technology

    • Report this post

    This week we have deep dive and took the formatting of the visuals to next level. This blog is centred around the possibilities that RankX and TopN functions provide in Power BI.#powerbidesktop #powerbihttps://lnkd.in/gQNBDHnZ

    Highlighting Top 10 with RankX and TopN analystinaction.blogspot.com
    Like Comment

    To view or add a comment, sign in

  • Akshay Waghavakar

    Power BI | SQL | Excel | Data Warehouse | Python learner

    • Report this post

    The DATESINPERIOD function in Power BI DAX is used to generate a table of dates that spans a specified time period. This function is commonly used to create date tables or to filter data within a specific date range.Here's the syntax of the DATESINPERIOD function:DATESINPERIOD(<dates>, <start_date>, <number_of_intervals>, <interval>)- `<dates>: This is a column or expression that returns a list of dates. It typically refers to a date column in your dataset or a function that generates a list of dates.- <start_date>: This is the starting date of the period.- <number_of_intervals>: This is the number of intervals to include in the period.- <interval>: This specifies the type of interval to use (e.g., "day", "month", "quarter", "year")-----------------------------------------------------------------Here's an example of how to use the DATESINPERIOD function to generate a table of dates for the current month:DatesInCurrentMonth = DATESINPERIOD('Date'[Date], TODAY(), 0, MONTH)This will create a table of dates for the current month based on the 'Date' column in your dataset.Similarly, you can specify different intervals to generate tables of dates for different time periods. For example, to generate a table of dates for the last 3 months:DatesLast3Months = DATESINPERIOD('Date'[Date], TODAY(), -3, MONTH)This will create a table of dates spanning the last 3 months.The DATESINPERIOD function is useful for creating dynamic date ranges for analysis and visualization in Power BI reports and dashboards.#dax #powerbi #analytics #linkdeincommunity #journey #improvement

    6

    Like Comment

    To view or add a comment, sign in

Akshay Waghavakar on LinkedIn: ๐Ÿ“Š Analytics Tip: Calculating Last Year Sales in Power BI using DAXโ€ฆ (28)

Akshay Waghavakar on LinkedIn: ๐Ÿ“Š Analytics Tip: Calculating Last Year Sales in Power BI using DAXโ€ฆ (29)

3,519 followers

  • 146 Posts

View Profile

Follow

Explore topics

  • Sales
  • Marketing
  • IT Services
  • Business Administration
  • HR Management
  • Engineering
  • Soft Skills
  • See All
Akshay Waghavakar on LinkedIn: ๐Ÿ“Š Analytics Tip: Calculating Last Year Sales in Power BI using DAXโ€ฆ (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Arielle Torp

Last Updated:

Views: 5732

Rating: 4 / 5 (61 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.