Skip to main content

PyDAX is designed to analyze DAX, it can extract comments, remove comments, and identify columns and measures referenced in DAX expressions.

Project description

PyDAX

PyDAX is a package designed to analyze DAX expressions. It can extract comments, remove comments, and identify columns and measures referenced in DAX expressions.

Installation

To install the package, use pip:

pip install PyDAXLexer

Usage

Here's a how to use PyDAXLexer. This example shows how to create a DAXExpression object and extract information.

from PyDAX import DAXExpression

if __name__ == '__main__':
    # DAX expression as string:
    dax_expression = """
    // Calculate average sales per customer, considering only active customers
    VAR SalesPerCustomer = 
        DIVIDE(
            SUM(Sales[TotalAmount]), 
            COUNTROWS(VALUES(Customers[CustomerID]))
        )
        
    // Calculate discount impact
    VAR DiscountImpact = 
        SUMX(
            FILTER(
                Sales,
                Sales[Discount] > 0
            ),
            Sales[DiscountAmount]
        )

    RETURN 
        IF(
            SalesPerCustomer > 500 && DiscountImpact < 1000,
            "High Value Customer",
            "Standard Customer"
        )
    """
    
    # Initialize the DAXExpression object
    expression = DAXExpression(dax_expression)
    
    # Access various properties
    print("Original Expression:", expression.dax_expression)
    print("Expression without Comments:", expression.dax_expression_no_comments)
    print("Table and Column References:", expression.table_column_references)
    print("Extracted Comments:", expression.comments)
    print("Cleaned Expression:", expression.clean_dax_expression)
    print("Contains Division Operator:", expression.contains_div)

Additional Features

The DAXExpression class provides several utility methods:

  • remove_comments(): Removes comments from the DAX expression.
  • extract_comments(): Extracts all comments in the expression.
  • extract_artifact_references(): Extracts table and column references.
  • generate_html(light: bool): Generates HTML output of the expression with syntax coloring.
  • save_html_to_file(file_name: str): Saves the syntax-colored HTML output to a file.

License

This project is licensed under the MIT License.

Acknowledgments

TabularEditor

The lexer grammar used in this project is adapted from the TabularEditor GitHub repository.

ANTLR

This project uses ANTLR (ANother Tool for Language Recognition) to generate the lexer and parser for DAX expressions.

  • Project: The ANTLR Project
  • License: BSD-3-Clause License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydaxlexer-0.1.4.tar.gz (53.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydaxlexer-0.1.4-py3-none-any.whl (51.8 kB view details)

Uploaded Python 3

File details

Details for the file pydaxlexer-0.1.4.tar.gz.

File metadata

  • Download URL: pydaxlexer-0.1.4.tar.gz
  • Upload date:
  • Size: 53.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for pydaxlexer-0.1.4.tar.gz
Algorithm Hash digest
SHA256 1a164ee077785a6edc927782b64a8b601bb38ba88fccd53fe31be986ff0d93de
MD5 f9c664dac236bd35d7cd4143541f5c9b
BLAKE2b-256 37a90b3716582564795f8987d13f77502c86776e09af95d95a26c5924043fd29

See more details on using hashes here.

File details

Details for the file pydaxlexer-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pydaxlexer-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 51.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for pydaxlexer-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 eed4158742f08d87154a2b1126efae5f1b7a48dde2311d0eb56d08d6d026e8d7
MD5 36a6fdbf4f0e51d0f80ae4c26d0cfdc8
BLAKE2b-256 98c178494802c80579ae7af1ff19e2d1e255e5d7470c7e49676be336d186ee54

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page